在 64 位和 32 位寄存器中搜索程序会导致 32 位
Searching programs in 64 bit and 32 bit registers results in 32 bit
我正在使用此方法: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();
}
我正在使用此方法: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();
}