Which Windows?


From time to time you probably need to know what version of Windows your application is running on.  If nothing else, it may help you help you troubleshoot a problem you've got, especially if the person at the other end of the phone is not quite as computer-literate as you'd like.

You can easily tell which version of Windows you are running on by a simple call to the GetVersionEx() API call. It's official description mentions "obtaining extended information about the version of the operating system that is currently running". If that's not good enough, I don't know what is.

The first thing to do is prototype it. It's C definition is

BOOL GetVersionEx(
  LPOSVERSIONINFO lpVersionInfo // version information
);

Basically it takes a pointer to a OSVersionInfo structure ( a group ) and returns a value telling us if it worked or not. If it did, we use the fields in the group to identify the operating system.  The Clarion prototype is:

MODULE('WIN32.LIB')
 GetVersionEx(Long),Bool,Raw,Pascal,Name('GetVersionExA')
END

The Clarion definition of the OSVersionInfo group is:

OSVersionInfo       Group,Type
dwOSVersionInfoSize ULong !Specifies the size, in bytes, of this data structure. 
dwMajorVersion      ULong !Major version number of the operating system
dwMinorVersion      ULong !Minor version number of the operating system
dwBuildNumber       ULong !See below
dwPlatformId        ULong !Identifies the operating system platform (Win32s/9x/NT) 
szCSDVersion        String(128) !See below
                    End

All of those fields are pretty straightforward, except for 2.

For Windows NT and Windows 2000 the dwBuildNumber field is the build number of the OS.  For Win9x (including Windows ME) the build number of the operating system in the low-order word and the high-order word contains the major and minor version numbers. 

For Windows NT and Windows 2000 the szCSDVersion field contains a null-terminated string that indicates the latest service pack installed on the system. If there is no SP then the field is empty.  For Win9x (including Windows ME) it contains "arbitrary additional information about the operating system" - IE it's empty.

Once you've got the prototype and OSVersionInfo group defined, it's basically a matter of filling in some CASE statements to determine which operating system you are running on.

    OVI:dwOSVersionInfoSize = Size(OVI)
    If GetVersionEx(Address(OVI)) = 0
      Message('Unable to determine what version of Windows you are on')
    Else
      Case OVI:dwPlatformId
      Of VER_PLATFORM_WIN32S
        ! Win32s on 16-bit Windows
      Of VER_PLATFORM_WIN32_WINDOWS
        ! Windows 95, Windows 98 or Windows ME
        ! If you need to tell the difference between different versions of the
        ! same OS (98 and 98SE) use OVI:dwBuildNumber 
        Case OVI:dwMinorVersion
        Of 0
          ! Windows 95
        Of 10
          ! Windows 98
        Of 90
          ! Windows ME
        Else
          ! ?? Unknown
        End
      Of VER_PLATFORM_WIN32_NT
        ! Windows NT, Windows 2000
        Case OVI:dwMajorVersion
        Of 3
          ! Windows NT 3.x
        Of 4
          ! Windows NT 4.x
        Of 5
          ! Windows 2000
        Else
          ! ?? Unknown
        End
      Else
        ! ?? Unknown
      End
    End

There are a couple of things to note:

1) If you need to determine a difference between different versions of Win9x., use the build number. In my experience Win98 is always 1111 and Win98SE is 2222.

2) If you do anything with the OVI:szCSDVersion under NT/2000 remove the null-terminating character first. (I can't remember why, but it definately fixed a problem I was having)

3) You can use the build number to uniquely identify what version of an operating system you are running IE WinME build 2525 is release candidate 1; WinNT 4 build 1314 is RC2. The June 2000 edition of the SysInternals Newsletter contained a table of build numbers for all versions of NT. If I've got it right it went something like this:

Version   Build #
WinNT 3.1 Beta 1 340
  Beta 2 397
  Release 511
WinNT 3.5 Beta 1 611
  Beta 2 683
  RC1 756
  Release 887
WinNT 3.51 Beta 1 944
  Release 1057
WinNT4 Beta 1 1234
  Beta 2 1314
  Release 1381
Win2000 Beta 1 1671
  Beta 2 1877
  RC0 of Beta 3 1946
  RC1 of Beta 3 2000.3
  Beta 3 2031
  RC 1 2072
  RC 2 2128
  RC 3 2183
  Release 2195
     

Download

WHATVER.ZIP (92K)


Back to my home page, my Clarion page, or send me mail at paula@attglobal.net

 

1