Getting windows version c

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.

Getting the Version of my C# app?

I am working on desktop application. I have create a setup.

Ex. My Application. Version is 1.0.0.

I want to get the current version of my desktop application which is 1.0.0 . I have tried by using Application.ProductVersion but it provides the version of my controls. (I am using DevExpress Control 15.2.7, so it provides the current version as 15.2.7 ).

Читайте также:  Driver для windows х64

How can I get the current version of the installed application? I want to compare it to the installed version to provide a «New Version Available» functionality for my product.

3 Answers 3

The info you are looking for is in AssemblyInfo.cs.

To access the info written in there at runtime you can use the System.Reflection.Assembly .

Use System.Reflection.Assembly.GetExecutingAssembly() to get the assembly (that this line of code is in) or use System.Reflection.Assembly.GetEntryAssembly() to get the assembly your project started with (most likely this is your app).

In multi-project solutions this is something to keep in mind!

Corresponding AssemblyInfo.cs:

Corresponding EXE-properties:

This may be important when working with InstallShield (see comments) !

Getting Windows OS version programmatically

I am trying to fetch Windows version with C# on my Windows 10 machine.

I always get those values (with C#\C++):

Which is Windows 8 OS, accordingly to MSDN

C# code:

C++ code

Windows 10 suppose to be with those:

  • (When I am taking a dump file from running process I can see that the OS version of that file is set to 10.0)

built by: 10.0.10586.0 (th2_release.151029-1700)

What am I missing here?

6 Answers 6

As the accepted answer is only for C#, here is a solution for C++.

It uses the RtlGetVersion in the ntdll.dll that uses the same structure as GetVersionEx (name is different, but the elements are the same) and gives you the correct version. As this function is normally used for driver development, the function is declared in the DDK and not in the SDK. So I used a dynamic solution to call the function. Please be aware that the ntdll.dll is loaded and released in every call. So if you need the function more often, keep the library loaded.

The structure pOSversion is pointing to must be initialized like for GetVersionEx.

Читайте также:  Windows adb usb driver

In my scenario I needed my application to capture computer info for possible bug-reports and statistics.

I did not find the solutions where an application manifest had to be added satisfactory. Most of the suggestions I found while googling this suggested just that, unfortunately.

Thing is, when using a manifest, each OS version has to be added manually to it in order for that particular OS version to be able to report itself at runtime.

In other words, this becomes a race condition: A user of my app may very well be using a version of my app that pre-dates the OS in use. I would have to upgrade the app immediately when a new OS version was launched by Microsoft. I would also have to force the users to upgrade the app at the same time as they updated the OS.

In other words, not very feasible.

After browsing through the options I found some references (surprisingly few compared to the app manifest) that instead suggested using registry lookups.

My (chopped down) ComputerInfo class with only WinMajorVersion , WinMinorVersion and IsServer properties looks like this:

Windows version in c# [duplicate]

I want to know which Windows version the PC has.. in C# Framework 3.5

I have tried using

OperatingSystem os = Environment.OSVersion;

Version ver = os.Version;

But the result is

Version minor: 2

The problem is that I have «Windows 8 Pro».

How can I detect it?

4 Answers 4

You will have to match version numbers with the appropriate string value yourself.

Here is a list of the most recent Windows OS and their corresponding version number:

  • Windows Server 2016 Technical Preview — 10.0*
  • Windows 10 — 10.0*
  • Windows 8.1 — 6.3*
  • Windows Server 2012 R2 — 6.3*
  • Windows 8 — 6.2
  • Windows Server 2012 — 6.2
  • Windows 7 — 6.1
  • Windows Server 2008 R2 — 6.1
  • Windows Server 2008 — 6.0
  • Windows Vista — 6.0
  • Windows Server 2003 R2 — 5.2
  • Windows Server 2003 — 5.2
  • Windows XP 64-Bit Edition — 5.2
  • Windows XP — 5.1
  • Windows 2000 — 5.0
Читайте также:  Xdebug phpstorm xampp windows

*For applications that have been manifested for Windows 8.1 or 10. Applications not manifested for 8.1 / 10 will return the Windows 8 OS version value (6.2).

Also, from the same source:

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using the Version API Helper functions to determine the operating system platform or version number, test for the presence of the feature itself.

C++ — Get Windows version

Im trying to get Windows version as result in C++. I have tried codes but it gives me wrong versions. Example:

Output: Windows version: 6.2 Im using Windows 10 and NT 6.2 corresponds to Windows 8/8.1. Im using CodeBlocks, Thanks for your replies.

1 Answer 1

With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

(I think what they actually mean by that is that the maximum version number that will be returned is the value you have in your manifest).

If you only want to run on Vista and later, then an easier way to get the Windows version is to use GetProductInfo(). This works without messing around with manifests (although you might want to do that for other reasons).

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