我们知道程序安装后,在注册表里的 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