在64位和32位寄存器中搜索程序将得到32位

问题描述 投票:0回答:1

我是从这里使用方法:Check if application is installed in registry查找“ Sql Server 2019”。

问题是当我在活动的解决方案平台上运行程序时:任何CPU。

string registryKey64 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string registryKey32 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";

RegistryKey key64 = Registry.LocalMachine.OpenSubKey(registryKey64);
RegistryKey key32 = Registry.LocalMachine.OpenSubKey(registryKey32);

然后输入key64 == key32。这导致它找不到64位sql服务器。问题不会在相反的方向发生。

我不想为64位平台运行程序。如何进入64位寄存器?

c# registry
1个回答
0
投票

我的解决方案:

string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey key64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
RegistryView.Registry64);
RegistryKey key = key64.OpenSubKey(registryKey);
if (key != null)
{
    var list = key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName).GetValue("DisplayName")).ToList();

    key.Close();
}
© www.soinside.com 2019 - 2024. All rights reserved.