Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect Windows 8.1 in a Desktop application

Tags:

windows

winapi

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.

like image 947
Tony Edgecombe Avatar asked Jul 01 '13 07:07

Tony Edgecombe


People also ask

How do I know which Windows 8.1 build I have?

To find out which version of Windows your device is running, press the Windows logo key + R, type winver in the Open box, and then select OK.

What is Windows 8.1 an operating system or application software?

Microsoft Windows 8.1 is an operating system (OS) for personal computers and tablet computers. Windows 8.1 runs on touchscreen devices as well as traditional computers that rely on a mouse and keyboard. Microsoft designed Windows 8.1 to address widespread complaints about Windows 8.


2 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

like image 76
user844541 Avatar answered Sep 30 '22 10:09

user844541


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
}
like image 33
Paul Avatar answered Sep 30 '22 09:09

Paul