我正在尝试获取此键中子键的所有显示名称:
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#.我尝试获取当前版本的操作系统:
OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;
Run Code Online (Sandbox Code Playgroud)
我上了Windows 10: 6.2.
但6.2是Windows 8或WindowsServer 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#中获取当前版本的最佳方法吗?