INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

System Information

How do I determine the Windows OS version? by Stretchwickster
Posted: 25 Feb 03 (Edited 4 Dec 07)

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;

Sources:
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

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close