您的位置:首页 > 编程语言 > C#

C#读取注册表,获取本机安装的软件清单

2010-01-09 17:06 288 查看
应一个网友的需求,写了下面的,获取本机安装的软件的清单,希望对有需要的人,有帮助吧

using Microsoft.Win32;


using (RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false))
{
if (key != null)
{
foreach (string keyName in key.GetSubKeyNames())
{
using (RegistryKey key2 = key.OpenSubKey(keyName, false))
{
if (key2 != null)
{
string softwareName = key2.GetValue("DisplayName", "").ToString();
string installLocation = key2.GetValue("InstallLocation", "").ToString();
if (!string.IsNullOrEmpty(installLocation))
{
this.textBox1.AppendText(string.Format("软件名:{0} -- 安装路径:{1}\r\n", softwareName, installLocation));
}
}
}
}
}
}


 

将取得的结果,放入 textBox1 中显示,每行一个。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: