问题
How to show the full Windows 10 build on C#?
I'm currently using Environment.OSVersion.VersionString
but it's not showing the full build number
The result:
Microsoft Windows NT 10.0.17134.0
But I want the last number, my full build: 10.0.17134.228
I want to know how can I show the last missing number. Not only where to find the number. The c# code to get it.
回答1:
The Windows 10 build number is stored in the registry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\
in the UBR
key.
Here's how to get it in code:
using Microsoft.Win32;
// ...
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
var buildNumber = registryKey.GetValue("UBR").ToString();
EDIT: Fixed the value name to get the correct number for OP. Credit for the correct key to Jorge Aguiar.
回答2:
You can get the last missing number at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UBR
(it's a DWORD value. It might be missing in some Windows versions.)
回答3:
You've to combine the 2 values to get "OS build":
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
var _UBR = registryKey.GetValue("UBR").ToString();
var _CurrentBuild = registryKey.GetValue("CurrentBuild").ToString();
string _version = _CurrentBuild+"."+ _UBR;
来源:https://stackoverflow.com/questions/52041735/c-sharp-how-to-show-the-full-windows-10-build-number