【问题标题】:Searching programs in 64 bit and 32 bit registers results in 32 bit在 64 位和 32 位寄存器中搜索程序会得到 32 位
【发布时间】:2020-05-07 12:24:54
【问题描述】:

我使用这个方法: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 server。问题不会发生在相反的方向。

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

【问题讨论】:

    标签: c# registry


    【解决方案1】:

    我的解决方案:

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 2010-09-15
      • 1970-01-01
      • 2022-01-15
      • 2013-11-25
      相关资源
      最近更新 更多