2

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.

saulob
  • 615
  • 1
  • 10
  • 25
  • [Microsoft Docs](https://learn.microsoft.com/en-us/dotnet/api/system.environment.osversion?redirectedfrom=MSDN&view=netframework-4.7.2#remarks) say: 'Starting with Windows 8, the OSVersion property returns the same major and minor version numbers for all Windows platforms. Therefore, we do not recommend that you retrieve the value of this property to determine the operating system version.' – nilsK Aug 27 '18 at 14:50
  • What do you recommend to check if the user is using the latest Windows version/build? The first 17134 version was released on April, but Microsoft released 9 new builds of it, how can I check if the user is using the latest one? – saulob Aug 27 '18 at 14:55
  • Sorry friend, i dont have a clue. Just stumbled over that link and wanted to share that information =) – nilsK Aug 27 '18 at 14:58
  • P-Invoke GetVersionEx - see [related question](http://stackoverflow.com/a/8406674/20257) – Yuval Peled Aug 27 '18 at 15:04
  • Possible duplicate of [Detecting Windows 10 OS Build minor version](https://stackoverflow.com/questions/47926094/detecting-windows-10-os-build-minor-version) – magicandre1981 Aug 28 '18 at 15:00
  • @magicandre1981 no. It's not related to c# .net commands – saulob Aug 28 '18 at 19:22
  • this makes no difference, it is the same question about getting the Revision number. – magicandre1981 Aug 29 '18 at 14:33
  • I included more details to explain that I want to know how to show not only how to find it. The c# command of it. @Lews Therin did that on his answer, added not only where but how to. – saulob Aug 30 '18 at 10:50

4 Answers4

5

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.

saulob
  • 615
  • 1
  • 10
  • 25
Lews Therin
  • 3,707
  • 2
  • 27
  • 53
3

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.)

1

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;
agileDev
  • 423
  • 5
  • 14
1

Cheesy way to get what you're asking for:

Process.Start(new ProcessStartInfo
        {
            FileName = @"C:\Windows\System32\cmd.exe",
            Arguments = "/c ver",
            RedirectStandardOutput = true,
            UseShellExecute = false
        }).StandardOutput.ReadToEnd().Trim();

Returns a string like:
Microsoft Windows [Version 10.0.19043.1052]

Truisms Hounds
  • 422
  • 4
  • 9