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

c# 如何获得你电脑安装的所有程序信息

2010-08-07 14:57 330 查看
我们知道程序安装后,在注册表里的 SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall 都会有记录.因此,我们利用这个记录就可以浏览我们电脑上安装的所有软件信息了. 代码实现如下:

private string Getinstalledsoftware()
{

string Software = null;

//The registry key:
string SoftwareKey = @"SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
{

foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{

if (!(sk.GetValue("DisplayName") == null))
{

if (sk.GetValue("InstallLocation") == null)
Software += sk.GetValue("DisplayName") + " - 路径未知/n"; //Nope, not here.
else
Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "/n"; //Yes, here it is...
}
}
catch (Exception ex)
{

}
}
}
}

return Software;
}

//EXAMPLE USAGE:

private void get_software_list_button__Click(object sender, RoutedEventArgs e)
{
//MessageBox.Show(Getinstalledsoftware());
this.textBox1.Text = Getinstalledsoftware();
}

源码下载地址: http://www.dengfeng.org/soft/AppShortcut.zip
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: