How to Determine Windows Version
Last updated: 7 January 2000
by Dolphinz

SUMMARY

This article will explain how to get Microsoft® Windows version installed on the system, using win32 assembly languaje.
The complete source code and program for this tutorial can be downloaded from here : WinVer


THEORY

The GetVersionEx( ) function supersedes the GetVersion( ) used on windows 16 bits, so futher new programs should use the new function to get windows version information.
The Win32 GetVersionEx( ) function returns information that a program can use to identify the operating system. Among those values are the major and minor revision numbers and a platform identifier. With the introduction of Windows 98, it now takes a more involved logical evaluation to determine which version of Windows is in use.

THE CODE

The listing below provides the data needed to evaluate the OSVERSIONINFO structure which is filled by GetVersionEx( ) function.

             OSVERSIONINFO STRUCT
               dwOSVersionInfoSize  DWORD      ?
               dwMajorVersion          DWORD      ?
               dwMinorVersion          DWORD      ?
               dwBuildNumber           DWORD      ?
               dwPlatformId              DWORD      ?
               szCSDVersion             BYTE 128 dup (?)
             OSVERSIONINFO ENDS
		
OSVERSIONINFO structure

Now let's look to the elements of this structure:

dwOSVersionInfoSize
This member carries the memory size of the structure. You need to set this to SIZE OSVERSIONINFO before calling the function.
dwMajorVersion
Identifies the major version number of the operating system.
dwMinorVersion
Identifies the minor version number of the operating system.
dwBuildNumber
  • Windows NT Identifies the build number of the operating system.
  • Windows 95 Identifies the build number of the operating system in the low-order word. The hi-order word contains the major and minor version numbers.
dwPlatformId
Identifies the operating system platform, and it can be:
Valor
Plataforma
VER_PLATFORM_WIN32s
Win32s on Windows 3.1.
VER_PLATFORM_WIN32_WINDOWS
Win32 on Windows 95.
VER_PLATFORM_WIN32_NT
Win32 on Windows NT.
szCSDVersion
  • Windows NT Contains a null terminated string, such as "Service Pack 3". If no Service Pack has been installed, the string is empty.
  • Windows 95 Contains a null terminated string, that provides arbitrary information about the operating system.


ANALIZING THE CODE

Now let's look at this piece of code which shows the usage of of the GetVersionEx( ) function in assembly languaje:

            .DATA
            ; Structures
            osver      OSVERSIONINFO        

            .CODE
            mov     osver. dwVersionInfoSize, SIZE OSVERSIONINFO
            call    GetVersionExA, offset osver
            .if     eax==0
                    ; Error. Not able to get OS information
                    ret
            .endif

At this point, if the call to GetVersionEx() was successful, that's the return value is different than NULL, then we have at OSVERSIONINFO data structure, the information required, so we can check the returned information.

When using the GetVersionEx( ) function to determine whether your application is running on a particular version of the operating system, check for version numbers that are greater than or equal to the desired version numbers.

This ensures that the test succeeds for later versions of the operating system. For example, if your application requires Windows 98, use the following test:
            ; Set the size of OSVERSIONINFO
		; and call the function
            mov     osver.dwOSVersionInfoSize, SIZE OSVERSIONINFO
            call    GetVersionExA, offset osver

            .if     (osver.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) &&
                    ((osver.dwMajorVersion>4) || ((osver.dwMajorVersion==4) &&
                    (osver.dwMinorVersion>0)))
                    Windows 98 detected
             .endif		
		

In order to check what type of Windows NT is installed on the system, we will have to access to the registry and check a key:
HKEY_LOCAL_MACHNE\System\CurrentControlSet\Control\ProductOptions
and read the value "ProductType" which can be one of these values:

  • WinNT     Windows NT WorkStation
  • ServerNT Windows NT Server
  • LanmanNT Windows NT Server-Domain Controller


  • In Windows 2000, this function returns more information than in other operating systems. To receive this extra information, you will use a new structure called OSVERSIONINFOEX.
    For more information about the OSVERSIONINFOEX data structure, refer to the documentation in the Windows 2000 SDK.



    Copyright © 1998, Dolphinz