Windows get build version

Use PowerShell to Find Operating System Version

April 25th, 2014

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find the version of his Windows operating system.

Microsoft Scripting Guy, Ed Wilson, is here. It is not a secret that I love Windows PowerShell. It is not a secret that I also love Windows 8.1 especially on my Surface Pro 2.

Disclaimer: I bought my Surface Pro 2 myself at the Microsoft Store in the mall. I paid the same price as everyone else does, and Istood in line to make the purchase just like everyone else does. I did so because I wanted one to take with me on my five week trip to Europe. It absolutely rocked.

Anyway, I love Windows PowerShell so much that I spend a lot of time playing around with it. I was on the Sapien blog the other night, and I ran across the following post by my friend, Alexander Riedel: Windows 8.1 breaks the version API. I thought to myself, «Hmmmm, I need to test this out.» In particular, he was referring to using the static OSVersion property from the System.Environment class in .NET. Here is the code:

When I opened the Windows PowerShell console to test this, I found that it works just fine. The code and associated output is shown here:

Well, I know that Alexander is a very intelligent and careful person. He certainly wouldn’t make wild accusations without backup or proof. So I opened the Windows PowerShell ISE and typed the same code. The results are shown here:

So it would seem that his blog post is correct. Except, it is not actually broken, and Alexander points to the Microsoft page that shows that this API is in fact deprecated in Windows 8.1: Operating system version changes in Windows 8.1 and Windows Server 2012 R2.

Deprecated, as you may know, means that you should quit using it because in future versions it may be removed and may no longer be supported. Sometimes a deprecated API works—other times it gives inconsistent results, as is the current case. The article states that the reason for this move is that a number of applications do not get shimmed properly because of poor version checks. For example, an application written for Windows XP would test for that version, and even though the app would work on Windows 8.1 it would refuse to run because it was specifically checking for Windows XP. The way around this, is to use an application manifest, which is something that most Windows PowerShell scripters will not be doing.

Testing out a theory

So I decided to test out a theory. I wonder if the GetVersion function would still work if I get it directly from the Kernel32.dll. I wrote a function that I call Get-OSVersion to see if it will work.

Читайте также:  Как отключить смену фона рабочего стола windows 10

The first thing I need to do is to go to Pinvoke.net and find the signature that I will need to use with the Add-Type command. Upon arriving at the site, I want to find Kernel32 in the left pane, and then under that section, I want to find the GetVersion function. This is pretty straightforward, and the site is shown in the following image:

Now that I have my signature, I use a HereString to store the signature as shown here:

public static extern uint GetVersion();

Now, I need to use the Add-Type cmdlet to add definition. I use –PassThru because I want the object that is created to be available to me. The command is shown here:

Add-Type -MemberDefinition $signature -Name «Win32OSVersion» -Namespace Win32Functions -PassThru

That is all there is to my function, so I close out the curly braces. The more complicated part of this comes in trying to parse the DWORD that the GetVersion function returns. So the first thing I need to do is convert the DWORD into bytes. To do this, I use the System.BitConverter .NET Framework class and I call the static GetBytes method. I pass it the function Get-OSVersion that I created, and I call the static GetVersion method from my object. This line is shown here:

The $OS variable contains an array of four bytes. The first element in the array contains the major version number, the second element contains the minor version. Because an array begins with 0, I grab elements 0 and 1 and store them in the appropriate variables as shownhere:

I need to take an array of the last two bytes and convert them from bytes into an integer. To do this, I once again use the System.BitConverter .NET Framework class, and I call the static ToInt16 method. It accepts an array and a position in the array as arguments. Here it is easy. My array is elements 2 and 3, and I start at the first position in the newly created array. This will be my build number. Here is the command that does this:

The last thing to do is display some output. I thought about creating an object. But dude, for this I was only trying to see if it worked. So I created a string by using the format specifier and substitution values.

For each portion in the following command, I substitute the value that is in the other side of the –F that occupies that position. So <0>will be replaced by the first item in my list—in this example, that is the value stored in the $MajorVersion variable.

«Version is <0>. <1>build <2>» -F $majorVersion,$minorVersion,$buildNumber

After all that work (it took me about an hour to write this), I finally run the script. And what happens? Yep, I proved that it lies about the operating system version. This is shown here:

So what is the answer? Dude (or dudette), it is easy. Use WMI. Here is the WMI code:

Note Remember, this is only a problem in Windows 8.1, so you should definitely be using Get-CimInstance and NOT using Get-WMIObject.

Here is the output. I see that it works properly, and it was a heck of a lot easier than messing around with the Kernel32 API:

That is all there is to using Windows PowerShell to find Windows operating system version information. Poshpourri Week will continue tomorrow when I will have a guest blog post from newly minted Windows PowerShell MVP, Dave Wyatt. The post is cool, and you don’t want to miss it.

Where can I find the Windows 10 version and build number Pro and Home?

Find out the Windows 10 version and the build number on Professional or Home, . here is the solution!

1.) . Version and Build Info via systeminfo or winver!
2.) . Show the Windows 10 Version and Build Number on the Desktop!
3.) . Show the Windows 10 Version and Build Number via Registry!!
4.) . Windows 10 Home or Pro version?

1.) Version and Build Info via systeminfo or winver!

Via Windows-10 Run [Windows Logo + R] and the command winver! (. see Image-1 Point 1)

Читайте также:  Wifi honey kali linux

or command prompt from Windows 10 and the systeminfo command
(. see Image-1 Point 4 and 5)

You can view a summary of important information about your Windows computer by opening System in Windows 10 Control Panel. You can see basic hardware information, such as your computer’s name, and you can change important system settings on by clicking the links in the left pane of System in Windows 10.

(Image-1) Windows 10 version and build number!

2.) Show the Windows 10 Version and Build Number on the Desktop!

  1. Please start the Windows Registry Editor (Windows-Logo+R or Windows-Logo+X).
  2. Navigate in the key HKEY_CURRENT_USER\Control Panel\Desktop
  3. set the «DWORD» value PaintDesktopVersion to:
    «0» don’t show the «Windows 10 Versionsnummer».
    «1» show the «Windows 10 Versionsnummer».
  4. the Windows 10 Version and Build Number is now on the Desktop!
    (. see Image-2 Arrow 1 to 4)

(Image-2) Windows 10 version and build number on the Desktop!

4.) Windows 10 Home or Pro version?

Find out : x64 / x32 Home or Pro:

►►► Do i have Windows 10 x86, x32 or x64 on my computer?

Windows 10 Home is similar to the Windows 7 Home Premium and the Windows 8 Home Version!

Windows 10 Pro is similar to: Windows 7 Professional / Ultimate, or Windows 8.1 Pro version.

The Windows 10 Home Edition: Is well suited for daily work and absolutely sufficient for standard users and gamers.

The Windows 10 Pro Edition: Is suitable for power users, developers and corporate networks.

Getting OS build version from Win32 Api C++

I am trying to find the build version of Windows Server 2016 machines, for example RS1 or RS3. There was an API to do this — GetVersionEx() — but is now deprecated.

MSDN says to use Version Helper Functions instead.

I want the build version, for ex: 1607 for RS1.

Is there an API to get this?

1 Answer 1

Option 0: (per RbMm) Use [RtlGetVersion] from the driver development kit.

Option 1: [Updated] Grab the version number of a system DLL like kernel32.dll. MSDN used to bless this approach, saying:

To obtain the full version number for the operating system, call the GetFileVersionInfo function on one of the system DLLs, such as Kernel32.dll, then call VerQueryValue to obtain the \StringFileInfo\\ProductVersion subblock of the file version information. [From an Internet Archive snapshot of MSDN circa 2017]

That would look something like this:

Note that the original MSDN link now redirects to a newer documentation set that doesn’t mention this approach. I suppose that means this is no longer a supported technique, and, presumably, all the compatibility hacks for older code might prevent an application from getting the actual answer.

Option 2: Query the registry, specifically:

which has values for CurrentMajorVersionNumber , CurrentMinorVersionNumber , and CurrentBuildNumber .

I can’t find official documentation for these values, so this may not be MSDN-approved or future-proof.

Option 3: Use GetProductInfo if available and fall back to GetVersionInfo if it’s not.

How to Find the Windows version, build and edition from ISO or DVD

Windows 10 ISO files downloaded from Microsoft will have descriptive names, such as en_windows_10_pro_10586_x64_dvd.iso and en_windows_10_pro_14393_x86_dvd.iso , depending upon the variant you downloaded. The file name depicts the language, version, build edition and the bitness of the Operating System contained in the ISO.

Let’s assume you have a copy of the Windows ISO with a generic name such as windows_10.iso (which doesn’t make any sense) obtained from a friend. To find the Windows version, build and edition from an ISO file or Windows Setup DVD, you can use the DISM tool.

Читайте также:  Linux and gma 3600

Find Windows version, build, edition from ISO file

To find the Windows version, build and edition from an ISO file or DVD, use these steps:

  1. Mount the ISO file by double clicking on it. By default, Mount will be the default action for ISO files. If not, right-click on the file and choose “Mount” in the context menu.
  2. Double-click the drive letter of the mounted drive.
  3. Double-click the Sources folder.
  4. Sort folder contents by Name, and look for a file named install.wim . If install.wim is missing, then you’ll have install.esd .

Install.esd located in the Sources folder.

Open an elevated Command Prompt window, and then type the following command:

In the ISO file, if you have install.esd instead of install.wim , you’d type:

DISM can handle both these file formats ( .wim & .esd ), at least in Windows 10.

Running DISM command on install.esd

You’ll see the following output:

If you’re using Windows 7, running the above DISM command-line with the .esd file name parameter would throw the following error:

In that case, you can pass boot.wim as the parameter, as below: Running DISM command on boot.wim

Which results in the following output:

Note that for Multi-arch ISO files that include both 32-bit and 64-bit versions of Windows, the boot.wim, install.wim, install.esd file path varies slightly. These files are located under their respective architecture folders.

That’s it! You’ve now obtained the maximum information about the Operating System included in an ISO file, such as the OS version, edition, Service Pack level, architecture.

DISM Get-WimInfo showing the wrong version?

Sometimes, the Windows 8 or 10 ISOs may have the wrong version info (header?) causing the above DISM command to show the wrong version or build.

I downloaded the Windows 20 20H2 ISO (20H2 Build starts with 19042.nnn) from Microsoft.

  • Filename: Win10_20H2_English_x64.iso
  • SHA-256: e793f3c94d075b1aa710ec8d462cee77fde82caf400d143d68036f72c12d9a7e

Running DISM showed this:

Whereas, 20H2 build starts with 19042.nnn (as shown by the winver command)

The setup.exe (inside the 20H1 ISO) file’s version showed up as 19041.xxx, instead of 19042.nnn. So, it’s a glitch in this particular ISO.

So, be aware of the above issues. The above can happen sometimes.

How to get Windows version from command prompt or from PowerShell

But is there a way to get the exact version string using command line output similar to the one mentioned in the image?

The attached is the output of «winver» command from run. PS: I am looking for a batch or PowerShell command.

There are some alternates available to get the Windows version like this PowerShell command:

6 Answers 6

The following commands are is going to help you with that. If you need more information, just type in systeminfo:

The ver command shows something like this:

But in PowerShell (or Git Bash) you have to call it through the cmd command:

I found it somewhere, PowerShell:

To add to @Bonifacio ‘s answer:

Would be even better, because it returns only the ReleaseId value, which you could then pipe to a file. Especially useful if you have several hosts to deal with.

With system information you can only get the build with that value and go to Google to get the respective version.

However, one simple way is by searching the registry on the command line:

The reg query way suggested all output a little garbage.

Using a for loop with tokens will output clean information.

The tokens=3 refers to the third word from the original output.

You will need to double the % if running inside a bat file.

You can set the output as a variable by replacing echo %i with set build=%i

Also remember to escape ^ any special characters.

Lastly look at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion for the string that has the required value. You may need to adjust the token count.

Оцените статью