獲取安裝軟件和路徑,通過注冊表得到。實例代碼:
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionUninstall", 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))
{
//將信息添加到ListView控件中
ListViewItem item = new ListViewItem(softwareName);
item.SubItems.Add(installLocation);
listView1.Items.Add(item);
}
}
}
}
}
}
}