Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I determine the Windows OS version?

System Information

How do I determine the Windows OS version?

by  Stretchwickster  Posted    (Edited  )
This is a revised version of the previous code I was displaying here, but now includes Windows Vista detection. Most of the credit should go to Brian Long (of The Delphi Magazine) who wrote a short article regarding Windows Versions (source at the bottom of the page).

This revised FAQ replaces the GetVersionEx API call with the Delphi RTL global variables: Win32Platform, Win32MajorVersion, Win32MinorVersion, Win32BuildNumber and Win32CSDVersion (all of which can be found in the SysUtils unit of Delphi). If you want to see how these variables are assigned then go to the InitPlatformId procedure of SysUtils. It now identifies Windows 95 OSR2 and Windows 98 SE as well as Service Pack information for the NT family of Operating Systems. I have included some information about Win32CSDVersion as a comment in the code.

Code:
function GetOS: String;
//--------------------------------------------------------------------------
// *** Information about Win32CSDVersion ***
// In the Win 9x family, Win32CSDVersion detects Win 95 OSR2 and Win 98 SE
// In the Win NT family, Win32CSDVersion detects Service Pack information
// CSD is an acronym for Corrective Service Disk
//--------------------------------------------------------------------------
var
  PlatformId, VersionNumber: string;
  CSDVersion: String;
begin
  CSDVersion := '';

  // Detect platform
  case Win32Platform of
    // Test for the Windows 95 product family
    VER_PLATFORM_WIN32_WINDOWS:
    begin
      if Win32MajorVersion = 4 then
        case Win32MinorVersion of
          0:  if (Length(Win32CSDVersion) > 0) and
                 (Win32CSDVersion[1] in ['B', 'C']) then
                PlatformId := '95 OSR2'
              else
                PlatformId := '95';
          10: if (Length(Win32CSDVersion) > 0) and
                 (Win32CSDVersion[1] = 'A') then
                PlatformId := '98 SE'
              else
                PlatformId := '98';
          90: PlatformId := 'ME';
        end
      else
        PlatformId := '9x version (unknown)';
    end;
    // Test for the Windows NT product family
    VER_PLATFORM_WIN32_NT:
    begin
      if Length(Win32CSDVersion) > 0 then CSDVersion := Win32CSDVersion;
      if Win32MajorVersion <= 4 then
        PlatformId := 'NT'
      else
        if Win32MajorVersion = 5 then
          case Win32MinorVersion of
            0: PlatformId := '2000';
            1: PlatformId := 'XP';
            2: PlatformId := 'Server 2003';
          end
        else if (Win32MajorVersion = 6) and (Win32MinorVersion = 0) then
          PlatformId := 'Vista'
        else
          PlatformId := 'Future Windows version (unknown)';
    end;
  end;
  VersionNumber := Format(' Version %d.%d Build %d %s', [Win32MajorVersion,
                                                        Win32MinorVersion,
                                                        Win32BuildNumber,
                                                        CSDVersion]);
  Result := 'Microsoft Windows ' + PlatformId + VersionNumber;
end;

[color red]Sources:[/color]
Revised Version:

"Windows Versions", The Delphi Clinic by Brian Long, The Delphi Magazine Issue 95 (July 2003)
Original Version:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
http://msdn2.microsoft.com/en-us/library/ms724833.aspx
http://www.mvps.org/access/api/api0055.htm
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top