
Introduction
I wrote this program to detect the operating system version under which my application is running. The GetVersionEx
function obtains extended information about the version of the operating system that is currently running. Here's the source code:
OSVERSIONINFO OSversion;
OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
::GetVersionEx(&OSversion);
switch(OSversion.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
m_sStr.Format("Windows %d.%d",OSversion.dwMajorVersion,OSversion.dwMinorVersion);
break;
case VER_PLATFORM_WIN32_WINDOWS:
if(OSversion.dwMinorVersion==0)
m_sStr="Windows 95";
else
if(OSversion.dwMinorVersion==10)
m_sStr="Windows 98";
else
if(OSversion.dwMinorVersion==90)
m_sStr="Windows Me";
break;
case VER_PLATFORM_WIN32_NT:
if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==0)
m_sStr.Format("Windows 2000 With %s", OSversion.szCSDVersion);
else
if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==1)
m_sStr.Format("Windows XP %s",OSversion.szCSDVersion);
else
if(OSversion.dwMajorVersion<=4)
m_sStr.Format("Windows NT %d.%d with %s",
OSversion.dwMajorVersion,
OSversion.dwMinorVersion,
OSversion.szCSDVersion);
else
m_sStr.Format("Windows %d.%d ",
OSversion.dwMajorVersion,
OSversion.dwMinorVersion);
break;
}
UpdateData(FALSE);
The data structure contains operating system version information:
typedef struct _OSVERSIONINFO{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
} OSVERSIONINFO;
dwOSVersionInfoSize
Specifies the size, in bytes, of this data structure.
dwMajorVersion
Identifies the major version number of the operating system. For example, for Windows NT version 3.51, the major version number is 3; and for Windows NT version 4.0, the major version number is 4.
dwMinorVersion
Identifies the minor version number of the operating system. For example, for Windows NT version 3.51, the minor version number is 51; and for Windows NT version 4.0, the minor version number is 0.
dwBuildNumber
Windows NT/2000: Identifies the build number of the operating system.
Windows 95/98: Identifies the build number of the operating system in the low-order word. The high-order word contains the major and minor version numbers.
dwPlatformId
Identifies the operating system platform.
szCSDVersion
Windows NT/2000: Contains a null-terminated string, such as "Service Pack 2", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
Windows 95/98: Contains a null-terminated string that provides arbitrary additional information about the operating system.
If we want to detect Windows CE then value of OSversion.dwPlatformId
is VER_PLATFORM_WIN32_CE
switch(OSversion.dwPlatformId)
{
case VER_PLATFORM_WIN32_CE:
m_sStr.Format("Windows CE %d.%d",
OSversion.dwMajorVersion,
OSversion.dwMinorVersion);
}
References
Microsoft Platform SDK : Windows System Information