110,537
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace 获取已安装程序列表
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string temp = null, tempType = null;
object displayName = null, uninstallString = null, releaseType = null;
RegistryKey currentKey = null;
int softNum = 0;
RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键
try
{
foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键
{
currentKey = pregkey.OpenSubKey(item);
displayName = currentKey.GetValue("DisplayName"); //获取显示名称
uninstallString = currentKey.GetValue("UninstallString"); //获取卸载字符串路径
releaseType = currentKey.GetValue("ReleaseType"); //发行类型,值是Security Update为安全更新,Update为更新
bool isSecurityUpdate=false;
if (releaseType != null)
{
tempType = releaseType.ToString();
if (tempType == "Security Update" || tempType == "Update")
isSecurityUpdate = true;
}
if (!isSecurityUpdate && displayName != null && uninstallString != null)
{
softNum++;
temp += displayName.ToString() + Environment.NewLine;
}
}
}
catch (Exception E)
{
MessageBox.Show(E.Message.ToString());
}
richTextBox1.Text = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
pregkey.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
private void GetProcessName()//
{
listBox1.Items.Clear();
foreach (Process p in Process.GetProcesses())
{
listBox1.Items.Add(p.ProcessName);
}
label1.Text = "统计:" + listBox1.Items.Count.ToString();
}