Windows version in c#

Diego picture Diego · Feb 12, 2014 · Viewed 18.9k times · Source

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

Plataform: WIN32NT

version 6.2.9200

Version minor: 2

Version Major: 6

The problem is that I have "Windows 8 Pro"...

How can I detect it?

Thanks

Answer

Crono picture Crono · Feb 12, 2014

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 & 2019 - 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

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

Here's the source.

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.