C# - How to show the full Windows 10 build number?

天大地大妈咪最大 提交于 2021-01-29 10:50:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!