Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinAPI deprecation after Windows 8.1

I have been using GetVersionEx and it failed in machine which runs with Windows 8.1. After looking some information found out that GetVersionEx is depracated since 8.1 version.

I want to ask where could I find full list of deprecated APIs because I don't want to use it anymore.

EDIT: I'm not asking what to use instead of GetVersionEx, I'm asking for a full list of deprecated APIs.

like image 880
ST3 Avatar asked Oct 22 '13 13:10

ST3


2 Answers

Microsoft has described the changes in Operating system version changes in Windows 8.1 and Windows Server 2012 R2. On the left of the article you can navigate to other issues related to Windows 8.1 and Windows Server 2012 R2 client and server compatibility.

The behavior you experience is the following:

In Windows 8.1, the 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, you will get Windows 8 versioning (6.2.0.0).

like image 173
Martin Liversage Avatar answered Nov 15 '22 04:11

Martin Liversage


Somebody on another forum pointed me to this approach.

Include your Windows 8.1 OS GUID in your application Manifest file

your .manifest should include Windows 8.1. and look like this.

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
   <application>
     <!--This Id value indicates the application supports Windows 8.1 functionality-->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

</application>

One issue with this approach is that your old binaries will always show the wrong Windows version on Windows 8.1 and later Windows Version.

another issue with this approach is that the GetVersionEx API is still deprecated so you will be not able to target Visual Studio 2013 Platform Toolset. You must set your Platform Toolset to Visual Studio 2012 or below.

Update: Actually I remembered you can disable that using something like this.

#pragma warning (disable : 4996)    
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
POSVERSIONINFO pVersionInfo = (POSVERSIONINFO)&versionInfo;
if (::GetVersionEx(pVersionInfo))
{
    if (6 == versionInfo.dwMajorVersion && 3 == versionInfo.dwMinorVersion)
    {
        wcout << _T("Windows 8.1 Detected") << endl;
    }
    else if (6 == versionInfo.dwMajorVersion && 2 == versionInfo.dwMinorVersion)
    {
        wcout << _T("Windows 8.0 Detected") << endl;
    }       
}
#pragma warning (default : 4996)

you could use a NetWkstaGetInfo API to get local machine's Version as well.

bool GetWindowsVersion(DWORD& major, DWORD& minor)
{   
    LPBYTE pinfoRawData;
    if (NERR_Success == NetWkstaGetInfo(NULL, 100, &pinfoRawData))
    {
        WKSTA_INFO_100 * pworkstationInfo = (WKSTA_INFO_100 *)pinfoRawData;
        major = pworkstationInfo->wki100_ver_major;
        minor = pworkstationInfo->wki100_ver_minor;
        ::NetApiBufferFree(pinfoRawData);
        return true;
    }
    return false;
}
int _tmain(int argc, _TCHAR* argv[])
{   
    DWORD major = 0;
    DWORD minor = 0;
    if (GetWindowsVersion(major, minor))
    {
        wcout << _T("Major:") << major << _T("Minor:") << minor << endl;
    }   
    return 0;
}

All that Said I have written two code samples to get Windows Version Without using GetVersionEx or GetVersion APIs. I have posted them on the bottom of the page. The issue is GetVersionEx API takes only about 10 Micro Seconds to Execute while my code samples take upward of 10-50 milliseconds to execute.

Getting Windows Version VerifyVersionInfo API

like image 30
Ehsan Samani Avatar answered Nov 15 '22 02:11

Ehsan Samani