Mega Code Archive

 
Categories / Delphi / System
 

How do I determine the Windows OS version

Title: How do I determine the Windows OS version? 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 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