相关疑难解决方法(0)

OpenSubKey()为我在regedit.exe中可以看到的注册表项返回null

我正在尝试获取此键中子键的所有显示名称:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Run Code Online (Sandbox Code Playgroud)

使用此代码:

     RegistryKey newKey;
     string val;

     string KeyPath64Bit = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
     RegistryKey mainKey = Registry.LocalMachine.OpenSubKey(KeyPath64Bit);

     string[] RegKeys64Bits = Registry.LocalMachine.OpenSubKey(KeyPath64Bit).GetSubKeyNames();

     foreach (string s in RegKeys64Bits)
     {
        newKey = mainKey.OpenSubKey(s);
        val = newKey.GetValue("DisplayName", -1, RegistryValueOptions.None).ToString();
        if (val != "-1")
           file64.WriteLine(val);
     }
Run Code Online (Sandbox Code Playgroud)

运行代码后,我找不到我需要的密钥之一:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}
Run Code Online (Sandbox Code Playgroud)

它应该有显示名称:Microsoft Visual C++ 2010 x64 Redistributable - 10.0.30319,但该GetSubKeyNames()方法给了我子键:{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}.KB2151757它没有任何显示名称.

为什么我不能得到我需要的确切子键({DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}),我怎么能得到它?

c# registry

71
推荐指数
2
解决办法
5万
查看次数

在C#中获取Windows 10中的当前版本操作系统

我用C#.我尝试获取当前版本的操作系统:

OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;
Run Code Online (Sandbox Code Playgroud)

我上了Windows 10: 6.2.

6.2Windows 8WindowsServer 2012(在.net中检测Windows版本)

我找到了以下解决方案(如何检测我的应用程序是否在Windows 10上运行).

static bool IsWindows10()
{
  var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
  string productName = (string)reg.GetValue("ProductName");
  return productName.StartsWith("Windows 10");
}
Run Code Online (Sandbox Code Playgroud)

这是在C#中获取当前版本的最佳方法吗?

c# operating-system version windows-10

3
推荐指数
1
解决办法
5324
查看次数

标签 统计

c# ×2

operating-system ×1

registry ×1

version ×1

windows-10 ×1