The information in this article applies to:
SUMMARYIn order to create a Win32-based application that takes advantage of the features of each platform, it is necessary to determine the operating system on which the application is currently running.
MORE INFORMATIONAccording to the documentation, the return value of GetVersion() is a DWORD that specifies the major and minor version numbers. GetVersionEx() uses members of the OSVERSIONINFO structure (dwMajorVersion and dwMinorVersion).
* The highest bit is 1. The remaining bits specify build number.
** The highest bit is 0. The remaining bits specify build number. *** The highest bit is 1. The remaining bits are reserved. The following sample code can be used to test the values returned by GetVersion(). Sample Code 1#include <windows.h> void main() { DWORD dwVersion; char szVersion[80]; dwVersion = GetVersion(); if (dwVersion < 0x80000000) { // Windows NT / 2000 wsprintf (szVersion, "Microsoft Windows NT/2000 %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion))); } else if (LOBYTE(LOWORD(dwVersion)) < 4) { // Win32s wsprintf (szVersion, "Microsoft Win32s %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion) & ~0x8000)); } else { // Windows 95/98 wsprintf (szVersion, "Microsoft Windows 95/98 %u.%u", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion)))); } MessageBox( NULL, szVersion, "Version Check", MB_OK ); } The following sample code can be used to test the values returned by GetVersionEx(). NOTE: The actual build number is derived by masking dwBuildNumber with 0xFFFF. Sample Code 2#include <windows.h> void main() { OSVERSIONINFO osvi; char szVersion [80]; memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); GetVersionEx (&osvi); if (osvi.dwPlatformId == VER_PLATFORM_WIN32s) wsprintf (szVersion, "Microsoft Win32s %d.%d (Build %d)", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF); else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) wsprintf (szVersion, "Microsoft Windows 95/98 %d.%d (Build %d)", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF); else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) wsprintf (szVersion, "Microsoft Windows NT/2000 %d.%d (Build %d)", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF); MessageBox( NULL, szVersion, "Version Check", MB_OK ); } In order to distinguish between Windows NT Workstation and Windows NT Server, use the registry API to query the following: \HKEY_LOCAL_MACHINE\SYSTEM \CurrentControlSet \Control \ProductOptions The result will be one of the following: WINNT Windows NT Workstation is running. SERVERNT Windows NT Server (3.5 or later) is running. LANMANNT Windows NT Advanced Server (3.1) is running. Additional query words: 1.20 3.10 3.50 4.00 detect Keywords : kbnokeyword kbKernBase kbWin32s kbWinOS95 kbWinOS98 kbGrpKernBase Version : winnt: Platform : winnt Issue type : kbhowto |
Last Reviewed: October 14, 1999 |