原文地址:http://hi.baidu.com/guigangsky/blog/item/da375f319a3f6a1ceac4af01.html/cmtid/c6ef9651d58acb15377abef1
//Registry.ClassesRoot 对应注册表 HKEY_CLASSES_ROOT
//Registry.CurrentConfig 对应注册表 HKEY_CURRENT_CONFIG
//Registry.CurrentUser 对应注册表 HKEY_CURRENT_USER
//Registry.LocalMachine 对应注册表 HKEY_LOCAL_MACHINE
//Registry.Users 对应注册表 HKEY_USERS
using System;
using Microsoft.Win32;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
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());
}
tbSoftWare.Text = "共有软件" + softNum.ToString() + "个"+ Environment.NewLine + temp;
pregkey.Close();
}
}
}
posted on 2010-06-12 17:37
漂漂 阅读(4154)
评论(0) 编辑 收藏 引用 所属分类:
c#开发