我是从这里使用方法: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位寄存器?
我的解决方案:
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();
}