1

I like to check if the running window is windows 8 or windows 8.1. With the Windows Major Check

6.2 -> Win 8

6.3 -> Win 8.1

That doesn't work, because with the release of Windows 8.1, the behavior of the GetVersion API has changed in the value it will return for the operating system version.

How can I still get the Version correctly?

Dark Side
  • 695
  • 2
  • 8
  • 18

2 Answers2

3

You could find that info in the registry of Windows. For example, if you have installed Windows 8.1 Pro Edition and execute this lines:

 using Microsoft.Win32;     
 //...

 var windowsName= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "ProductName","");
 var version= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentVersion", "");
 var build= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentBuild", "");

You will get Windows 8.1 Pro, 6.3 and 9600 respectively.

Also you could use the WMI to get the Windows name, check the answer in this post:

public static string GetOSFriendlyName()
{
  string result = string.Empty;
  ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
  foreach (ManagementObject os in searcher.Get())
  {
    result = os["Caption"].ToString();
    break;
  }
  return result;
}
Community
  • 1
  • 1
ocuenca
  • 38,548
  • 11
  • 89
  • 102
2

try this

it concats the major version no followed by the minor version there are many methods to play with according here Environment Class (System)

string ver = Environment.OSVersion.Version.Major + "." + Environment.OSVersion.Version.Minor;

and the output would be:

6.2

Community
  • 1
  • 1
  • While this code block may answer the question, it would be best if you could provide a little explanation for why it does so. – David Mar 22 '15 at 16:22
  • But there is a note that says "The OSVersion property reports the same version number (6.2.0.0) for both Windows 8 and Windows 8.1." – Ben Voigt Mar 23 '15 at 00:22