Get windows version from files

Find windows OS version from command line

Windows has command line utilities that show us the version of the Windows OS running on the computer, including the service pack number. There are multiple CMD commands that help with finding this, you can pick the one that suits your need. Ver command can show you the OS version whereas Systeminfo command can additionally give you service pack, OS edition and build number etc.

Find OS Version and Service Pack number from CMD

As you can see above, ver command shows only OS version but not the service pack number. We can find service pack number as well with Systeminfo command. Systeminfo dumps lot of other information too, which we can filter out using findstr command.

This command works on XP, Vista and Windows 7 and on Server editions also. Find below example for Win7.

In case of Windows 7 SP1, the output would be slightly different as below.

If you want to print more details, then you can use just ‘OS’ in the findstr search pattern. See example below for Server 2008.

Check Windows version using WMIC command

Run the below WMIC command to get OS version and the service pack number.

Example on Windows 7:

If you want to find just the OS version, you can use ver command. Open command window and execute ver command. But note that this does not show service pack version.

This command does not show version on a Windows 7 system.

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.

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 .exe file version number from file path

I am using .Net 3.5/4.0 with code in C#.

I am trying to get a version number of an exe file on my C: drive.

For example path is: c:\Program\demo.exe. If the version number of demo.exe is 1.0.

How can i use this path to grab version number?.

7 Answers 7

You can use FileVersionInfo.FileVersion to fetch this from a path.

Updated and modernized 2018 (e.g. string interpolation of C#6):

The accepted answer is partly not correct (ProductVersion is not typically returning three-part version) and a bit misleading:

Here is a more complete answer. To get the main text not too lengthy I splitted it in a short(er) summary which may be «enough» for a lot of people. You are not obliged to read the detailed second part, so please no tl;dr 🙂

Short summary:

There are different versions (assembly version, file version, product version) of each file, but normally you will have them all equal to not get «version hell» already on file level (it will come early enough).

The file version (which is visible in Explorer and used in setups/installations) is, what I would name the most important to bother.

To achieve this, simply comment out fileversion in AssemblyInfo.cs file as below. This assures that the three possible different versions of one file are the same!

[assembly: AssemblyVersion(«1.1.2.«)]
//[assembly: AssemblyFileVersion(«1.1.2.
«)]

E.g. for Semantic versioning you want to get only 3 version parts out of possible 4 :

Having an automatic build counting for every Visual Studio build is useful. But this build counting is not always useful to tell your customers, internal or external. So for mentioning the file version to windows, in title dialogs, I would advice to show only three parts v1.2.3 (and of course with semantic versioning):

FileVersionFull2 is just showing how to handle all 4 parts, except the «V» it contains the same as FileVersionFull .

D e t a i l s:

First is a cheat sheet about how to get and set the three versions:

File version: [assembly: AssemblyFileVersion(..)] => System.Diagnostics.FileVersionInfo.FileVersion

Product version: [assembly: AssemblyInformationalVersion(..)] => System.Diagnostics.FileVersionInfo.ProductVersion

Assembly version: [assembly: AssemblyVersion(..)] => System.Reflection.Assembly.Version

Especially the defaulting may be confusing. Recommended SO link to understand details: FileVersionInfo and AssemblyInfo

EntryAssembly vs. ExecutingAssembly
For fully considering every case for getting the version of the running app, search elsewhere for more details, e.g. here: Which is better for getting assembly location , GetAssembly().Location or GetExecutingAssembly().Location
Especially, there can be confusion, if EntryAssembly or ExecutingAssembly should be used. They both have advantages and caveats. If you have the following code not in the same assembly as the .exe, e.g. in a helper assembly, things get more complicated. Usually you would use EntryAssembly then, to get the version of the .exe.
But: For unit tests in Visual Studio to test routines in a parallel .exe project, GetEntryAssembly() doesn´t work (my env: NUnit, VS2017). But GetExecutingAssembly() doesn´t crash at least, only during unit test you get the assembly version of the test project. Fine enough for me.There may be situations which are not as simple.
If wanted, you can omit the declaration as static making it really possible to get versions of several different assemblies in one program.

Product version vs. file version:
ProductVersion of a file is shown in Windows Explorer too. I would recommend to maximally differentiate ProductVersion and FileVersion in the most «customer-visible» file (mostly the main .exe of application). But it could be of course a choice to differentiate for every file of the «main» app and let them all have them all the «marketing» ProductVersion which is seen by customer. But experience shows that it is neither necessary nor cheap to try to synchronize technical versions and marketing versions too much. Confusion doesn´t decrease really, costs increase. So the solution described in the first part here should do it mostly.

Windows: Command line to read version info of an executable file?

Does Windows have an executable that I can run in the command shell which returns the version number of an executable (.exe) file?

I see a lot of questions that show how to do it from different languages, and references to third party software to write it, but I can’t find a simple shell command to do it. Additional points if I don’t need to install anything.

It must be run as normal user. Not administrator.

7 Answers 7

You can use wmic to do it. And you can wrap it into a batch file

Save it as (example) getVersion.cmd and call as getVersion.cmd «c:\windows\system32\msiexec.exe»

edited to adapt to comments and not require administrator rights. In this case, an hybrid cmd/javascript file is used to query wmi. Same usage

If you are willing and able to use PowerShell, the following code will work. If you are on a supported Windows system, PowerShell will be available.

If you must run it in a cmd.exe shell, you could use:

This will give you only the file version:

and one way with makecab :

example output (it has a string version which is a small addition to wmic method 🙂 ):

also you can take a look at tooltipinfo.bat

filever c:\windows\system32\notepad.exe (the filever is preinstalled on every Windows OS).

filever.exe is in SUPPORT.CAB from the Windows 2003 Support tools, and maybe other places.

A method using VBScript and Scripting.FileSystemObject from a CMD script

A variant of the powershell method, if you are calling from a CMD script. Using FileVersionRaw instead of FileVersion, because FileVersion can have extra text decoration, but have to ToString() to get the expected format.

A Powershell from CMD method to compare versions, as that could be the reason for asking in the first place. Have to use %ErrorLevel%==x because ErrorLevel==x is actually greater or equal.

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.

Читайте также:  Xps viewer windows 10 offline installer
Оцените статью