The version number of the user's Windows operating system that was inferred in the code was obtained by getversion or GetVersionEx, and then compared.
Today, the new Visual Studio provides new functions to infer the system version number, which is much more convenient than calling the API directly.
In order to use the new function. Need to use SDK 8.1. I used the VS2013. Already brought it.
#include "stdafx.h" #include <iostream> #include <windows.h>//VersionHelpers.h dependent on Windows.h#include < versionhelpers.h>//Windows SDK 8.1 has a using namespace std;int _tmain (int argc, _tchar* argv[]) {//is greater than or equal to XPif (is Windowsxporgreater ()) cout << ">= xp" << endl;elsecout << "< XP" << endl;//is greater than or equal to XP sp1if (Iswindowsxpsp1orgreater ()) cout << ">= xp SP1" << endl;elsecout << "< XP SP1" << endl;//whether Greater than or equal to XP sp2if (Iswindowsxpsp2orgreater ()) cout << ">= xp SP2" << endl;elsecout << "< XP SP2" <& Lt endl;//is greater than or equal to XP sp3if (Iswindowsxpsp3orgreater ()) cout << ">= xp SP3" << endl;elsecout << "< XP SP3 "<< endl;//is greater than or equal to Vistaif (Iswindowsvistaorgreater ()) cout <<" >= Vista "<< endl;elsecout <&L T "< Vista" << endl;//is greater than or equal to Vista sp1if (Iswindowsvistasp1orgreater ()) cout << ">= Vista SP1" << E Ndl;elsecout << "< Vista SP1 "<< endl;//is greater than or equal to Vista sp2if (Iswindowsvistasp1orgreater ()) cout <<" >= Vista SP2 "<< Endl;elsecout << < Vista SP2 << endl;//is greater than or equal to Win8if (Iswindows8orgreater ()) cout << ">= Win8" << endl;elsecout << < Win8 << endl;//is greater than or equal to Win8.1if (Iswindows8point1orgreater ()) cout << ">= Win8.1" << endl;elsecout << "< Win8.1" << endl;//is the server version if (Iswindowsserver ()) cout <&L T "Server Edition" << endl;elsecout << "non-server Edition" << endl;//functions are implemented through Iswindowsversionorgreater//Windows The 2000 version is 5.0, so we can also infer if (Iswindowsversionorgreater (5, 0, 0)) cout << ">= Win" << endl;elsecout << "< Win" << endl;system ("pause"); return 0;}
Win7 x64 Ultimate Performance:
Other than that. Suppose you chose the platform toolset to support XP. You cannot use the above function, you will be prompted to find the VersionHelper.h header file.
New method for inferring Windows version number