最近在做一个程序,想读出本机所有安装的程序,从H_L_M\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall下读取所有项的DisplayName键值,我是这样写的,但无法取到想要的结果?而且,总是提示“不允许所请求的注册表访问权”如何解决?string res = "";
RegistryKey Key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", true);
string[] valueList = Key.GetSubKeyNames();
foreach (String s in valueList)
{
RegistryKey Key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" + "\\" + s, true); //进入子项
string[] softname = Key1.GetValueNames();
foreach (String ss in softname)
{
if (ss == "DisplayName")
{
res += runKey.GetValue(ss).ToString() + "\n\r";
MessageBox.Show(res);
}
}
}
RegistryKey Key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", true);
string[] valueList = Key.GetSubKeyNames();
foreach (String s in valueList)
{
RegistryKey Key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" + "\\" + s, true); //进入子项
string[] softname = Key1.GetValueNames();
foreach (String ss in softname)
{
if (ss == "DisplayName")
{
res += runKey.GetValue(ss).ToString() + "\n\r";
MessageBox.Show(res);
}
}
}
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))
{ }
}
}
}
}
}