In the Windows 8.1 preview Environment.OSVersion.Version returns the same version numbers as Windows 8. Is there alternative way of detecting Windows 8.1.
-
4You've tagged this as [tag:winapi] and yet you reference `Environment.OSVersion` which is a .NETism. Which do you need a solution for? – Damien_The_Unbeliever Jul 01 '13 at 07:28
-
3Checking the version number of the OS is really *not* the best way of determining whether a particular feature is supported. Why do you need to know if you're running on Windows 8 or 8.1? What problem are you trying to solve? – Cody Gray - on strike Jul 01 '13 at 07:30
-
3It is not. I just encountered the same issue. the version is 6.2.9200 which is the same as win 8. – user844541 Jul 01 '13 at 14:08
-
2Cody, In this case it is the best way, the functionality I need is deep in the print spooler, testing for it would not make for an attractive user experience. – Tony Edgecombe Jul 17 '13 at 10:54
4 Answers
Take a look at this article:
Operating system version changes in Windows 8.1 Preview
GetVersion(Ex)
APIs have been deprecated. That means that while you can still call the APIs, if your app does not specifically target Windows 8.1 Preview, you will get Windows 8 versioning (6.2.0.0).
What it says is that GetVersion
lies to you about the real OS version unless you explicitly direct 8.1 in your manifest.
You need to add the following to the app manifest:
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
* <!-- Windows 8.1 -->
* <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
If you don't want to do that you can check the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Current version will give you 6.3
Current build nmber will be 9431

- 55
- 9

- 2,868
- 5
- 32
- 60
-
So we should add *all* of those supported OS keys to the manifest (assuming that we support them all)? Or we should only add the *latest* supported OS? – Cody Gray - on strike Jul 02 '13 at 04:00
-
I think that you should add all of them. if not in the MSDN doc they should have wrote only *
– user844541 Jul 02 '13 at 08:04 -
I guess Windows 7 won't know the GUID of Windows 8 yet, so if you don't want to run into problems on Windows 7, include them all. Sounds logical, hm? ;-) – ygoe Jul 07 '13 at 11:16
-
1
Another possibility is to use the VerifyVersionInfo
function, which returns the correct result even if your application doesn't have the corresponding manifest file mentioned by user844541.
Example:
BOOL CompareWindowsVersion(DWORD dwMajorVersion, DWORD dwMinorVersion)
{
OSVERSIONINFOEX ver;
DWORDLONG dwlConditionMask = 0;
ZeroMemory(&ver, sizeof(OSVERSIONINFOEX));
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
ver.dwMajorVersion = dwMajorVersion;
ver.dwMinorVersion = dwMinorVersion;
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL);
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL);
return VerifyVersionInfo(&ver, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);
}
Usage:
if(CompareWindowsVersion(6, 3))
{
// Windows 8.1
}

- 6,061
- 6
- 39
- 70
-
3Note to anyone finding this that this method does not work for Windows 10 – Matt Wilko Jul 10 '15 at 14:50
Use ntdll!RtlGetVersion
. This is what both GetVersionEx
and VerifyVersionInfo
use, and it gives the correct version number. It takes a pointer to an OSVersionInfoExW
structure, like GetVersionExW
does. If it succeeds, it returns STATUS_SUCCESS
(0).

- 18,630
- 11
- 38
- 46

- 61
- 1
- 1
-
1will "RtlGetVersion" not be affected by the default OSVersionLie shim? also not with windows 10? can you extend your answer by giving some references? – Opmet Apr 23 '15 at 10:06
-
I've tried RtlGetVersion and it is not affected by the shim - it returned 10 (VerifyVersionInfo did not, unless the manifest was updated). – FruitBreak Feb 05 '16 at 12:27
-
This should be the most upvoted and the accepted answer, simply because it's the better one. The manifest tool creates more hassle than it solves problem for anything that's a little outside the box Microsoft has thought for it. _This_ simply works around it. – 0xC0000022L Feb 26 '16 at 15:08
-
@0xC0000022L, at least for now. No telling what will happen with the next version of Windows. My "What version of Windows is this?" routine is now up to eight different methods, in the hope that at least one will keep working in the future. – Mark Mar 24 '16 at 22:00
-
@Mark: Given MSFT proclaimed Windows 10 is going to be the last Windows version? ... *smirk* – 0xC0000022L Mar 25 '16 at 00:39
I'm not sure that you will want to go this deep but it is easily possibly to get exact operating system version through a simple WMI query call as described below. I've mentioned a method which you can plug directly in your code to get the exact operating system version. Required namespaces to be imported for this C# code snippet have been mentioned just above the function :
using System;
using System.Management;
private string GetOsVersion()
{
var sccmManagementScope = new ManagementScope(@"\\" + System.Environment.MachineName + @"\root\cimv2");
var searchResult = new ManagementObjectSearcher(sccmManagementScope, new WqlObjectQuery("SELECT Version FROM Win32_OperatingSystem"));
var resultSet = searchResult.Get();
var osVersion = string.Empty;
foreach (ManagementObject managementObject in resultSet)
{
osVersion = Convert.ToString(managementObject["Version"]);
}
return osVersion;
}
Though I still strongly believe that System.Environment.OSVersion.Version
should be able to meet most of your needs unless you have something very specific in regards to target Windows 8.1. In fact I used the same trick for one of requirements as System.Environment
class actually lies about the OS version if your application is not manifested for Windows 8.1 operating system.

- 24,161
- 21
- 159
- 240