Microsoft KB Archive/92395

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows NT
 * Microsoft Windows versions 95, 98
 * Microsoft Win32s versions 1.25, 1.3
 * Microsoft Windows 2000

-

SUMMARY
In 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.

You can use GetVersion or GetVersionEx to determine what operating system and version your application is running under.

NOTE: GetVersion is supported on Windows 3.1, but GetVersionEx is new to the Win32 API. A Win32-based application might be running under MS-DOS/Windows using the Win32s extension, Windows NT, Windows 2000, Windows 95, or Windows 98.

MORE INFORMATION
According 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 following table shows the return values from GetVersion under various environments:

 * The highest bit is 1. The remaining bits specify build number. "Note that the version of MS-DOS cannot be determined as it can under Windows 3.x."  ** The highest bit is 0. The remaining bits specify build number. The following sample code can be used to test the values returned by GetVersion.
 * The highest bit is 1. The remaining bits are reserved.

Sample Code 1
#include 

void main {  DWORD dwVersion; char szVersion[80];

dwVersion = GetVersion;

if (dwVersion < 0x80000000) { // Windows NT / 2000 wsprintf (szVersion, &quot;Microsoft Windows NT/2000 %u.%u (Build: %u)&quot;,               (DWORD)(LOBYTE(LOWORD(dwVersion))),                (DWORD)(HIBYTE(LOWORD(dwVersion))),                (DWORD)(HIWORD(dwVersion))); }  else if (LOBYTE(LOWORD(dwVersion)) < 4) { // Win32s wsprintf (szVersion, &quot;Microsoft Win32s %u.%u (Build: %u)&quot;,               (DWORD)(LOBYTE(LOWORD(dwVersion))),                (DWORD)(HIBYTE(LOWORD(dwVersion))),                (DWORD)(HIWORD(dwVersion) & ~0x8000)); } else { // Windows 95/98 wsprintf (szVersion, &quot;Microsoft Windows 95/98 %u.%u&quot;,               (DWORD)(LOBYTE(LOWORD(dwVersion))),                (DWORD)(HIBYTE(LOWORD(dwVersion)))); }

MessageBox( NULL, szVersion, &quot;Version Check&quot;, 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 

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, &quot;Microsoft Win32s %d.%d (Build %d)&quot;,               osvi.dwMajorVersion,                osvi.dwMinorVersion,                osvi.dwBuildNumber & 0xFFFF); else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) wsprintf (szVersion, &quot;Microsoft Windows 95/98 %d.%d (Build %d)&quot;,               osvi.dwMajorVersion,                osvi.dwMinorVersion,                osvi.dwBuildNumber & 0xFFFF); else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) wsprintf (szVersion, &quot;Microsoft Windows NT/2000 %d.%d (Build %d)&quot;,               osvi.dwMajorVersion,                osvi.dwMinorVersion,                osvi.dwBuildNumber & 0xFFFF);

MessageBox( NULL, szVersion, &quot;Version Check&quot;, 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
 * }