Operating System Version

methods

1. GetVersion

DWORD WINAPI GetVersion(void);


The following illustration shows the format of the bits in system version.
+-------------+----------+-------------------------+
|   Reserved  | Build Id |  Minor    |   Major     |
+-------------+----------+-------------------------+
31         30 29      16 15        8 7             0   bit

example:

    DWORD dwVersion = 0;
    DWORD dwMajorVersion = 0;
    DWORD dwMinorVersion = 0;
    DWORD dwBuild = 0;

    dwVersion = GetVersion();
 
    // Get the Windows version.

    dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
    dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));

    // Get the build number.

    if (dwVersion < 0x80000000)              
        dwBuild = (DWORD)(HIWORD(dwVersion));
    

    printf("Version is %d.%d (%d)\n", 
                dwMajorVersion,
                dwMinorVersion,
                dwBuild);


2. GetVersionEx function

BOOL WINAPI GetVersionEx(
  __inout  LPOSVERSIONINFO lpVersionInfo
);

example:

	OSVERSIONINFO _osv;
	ZeroMemory(&_osv, sizeof(OSVERSIONINFO));
	_osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	::GetVersionEx(&_osv);
	cout<<"Major:"<<_osv.dwMajorVersion<<endl;
	cout<<"Minor:"<<_osv.dwMinorVersion<<endl;
	cout<<"Build:"<<_osv.dwBuildNumber<<endl;
	cout<<"Platform:"<<_osv.dwPlatformId<<endl;
	cout<<"Others:"<<_osv.szCSDVersion<<endl;





Reference

The following table summarizes the most recent operating system version numbers.

Operating systemVersion number
Windows 8 6.2
Windows Server 2012 6.2
Windows 7 6.1
Windows Server 2008 R2 6.1
Windows Server 2008 6.0
Windows Vista 6.0
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 5.1
Windows 2000 5.0



原文地址:https://www.cnblogs.com/rogerroddick/p/2846690.html