尝试从 C# 获取时本地计算机注册表项值不匹配
Local Machine Registry Key values not matching when trying to fetch from C#
我正在尝试从注册表中获取所有已安装应用程序的列表,但从注册表中获取键值
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
与我的代码获取的值不匹配。
从本地获取密钥的代码片段Machine_32 - 类似于 CurrentUser 和本地机器 64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") != null ? subkey.GetValue("DisplayName").ToString() : "";
version = subkey.GetValue("DisplayVersion") != null ? subkey.GetValue("DisplayVersion").ToString() : "";
install_date = subkey.GetValue("InstallDate") != null ? subkey.GetValue("InstallDate").ToString() : "";
publisher = subkey.GetValue("Publisher") != null ? subkey.GetValue("Publisher").ToString() : "";
install_location = subkey.GetValue("InstallSource") != null ? subkey.GetValue("InstallSource").ToString() : "";
if (displayName != "")
{
installedAppsB.Add(new SoftwareInventory()
{
key = keyName,
app_name = displayName,
version = version,
install_date = install_date,
publisher = publisher,
install_location = install_location,
reg_source = "LM-SOFTWARE-Microsoft-Windows-CurrentVersion-Uninstall"
});
}
}
例如,我在我的记录中没有看到 Node.js
,但它在我的注册表中。
注册表
来自我的代码的数据
我尝试使用 app.manifest
中的以下值提升权限:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
但仍然没有帮助。
我还尝试匹配 NirSoft UnintallView 找到的所有已安装应用程序的列表,它正在查找 108 Apps
与我的代码查找 186 Apps
查找所有 CurrentUser
,LocalMachine_32
& LocalMachine_64
注册表。
我在这里做错了什么。请指教,谢谢
当我将配置更改为 x64
时,我的 Visual Studio 上的调试选项设置为 Any CPU
我的代码能够从正确的注册表项中获取值,即 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
并且没有像@Charlieface 和@MatthewWatson 在评论中提到的那样重定向到 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
。
我正在尝试从注册表中获取所有已安装应用程序的列表,但从注册表中获取键值
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
与我的代码获取的值不匹配。
从本地获取密钥的代码片段Machine_32 - 类似于 CurrentUser 和本地机器 64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") != null ? subkey.GetValue("DisplayName").ToString() : "";
version = subkey.GetValue("DisplayVersion") != null ? subkey.GetValue("DisplayVersion").ToString() : "";
install_date = subkey.GetValue("InstallDate") != null ? subkey.GetValue("InstallDate").ToString() : "";
publisher = subkey.GetValue("Publisher") != null ? subkey.GetValue("Publisher").ToString() : "";
install_location = subkey.GetValue("InstallSource") != null ? subkey.GetValue("InstallSource").ToString() : "";
if (displayName != "")
{
installedAppsB.Add(new SoftwareInventory()
{
key = keyName,
app_name = displayName,
version = version,
install_date = install_date,
publisher = publisher,
install_location = install_location,
reg_source = "LM-SOFTWARE-Microsoft-Windows-CurrentVersion-Uninstall"
});
}
}
例如,我在我的记录中没有看到 Node.js
,但它在我的注册表中。
注册表
来自我的代码的数据
我尝试使用 app.manifest
中的以下值提升权限:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
但仍然没有帮助。
我还尝试匹配 NirSoft UnintallView 找到的所有已安装应用程序的列表,它正在查找 108 Apps
与我的代码查找 186 Apps
查找所有 CurrentUser
,LocalMachine_32
& LocalMachine_64
注册表。
我在这里做错了什么。请指教,谢谢
当我将配置更改为 x64
时,我的 Visual Studio 上的调试选项设置为 Any CPU
我的代码能够从正确的注册表项中获取值,即 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
并且没有像@Charlieface 和@MatthewWatson 在评论中提到的那样重定向到 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
。