Windows version
This article applies to Windows only.
See also: Multiplatform Programming Guide
│
Deutsch (de) │
English (en) │
русский (ru) │
This article is about Windows programming. Obtaining information on the version of the running Windows instance is important for many purposes.
Using Win32Proc Lazarus unit
The following works for identifying Windows 11 and all older versions:
uses ..., Win32Proc;
function WindowsVersionName: string;
begin
case WindowsVersion of
wv95: Result:= 'Windows 95';
wvNT4: Result:= 'Windows NT v.4';
wv98: Result:= 'Windows 98';
wvMe: Result:= 'Windows Me';
wv2000: Result:= 'Windows 2000';
wvXP: Result:= 'Windows XP';
wvServer2003: Result:= 'Windows Server 2003';
wvVista: Result:= 'Windows Vista';
wv7: Result:= 'Windows 7';
wv8: Result:= 'Windows 8';
wv8_1: Result:= 'Windows 8.1';
wv10: Result:= 'Windows 10';
wv11: Result:= 'Windows 11';
else Result:= '?';
//See possible values in the unit "win32proc" in "lcl/interfaces/win32/win32proc.pp"
end;
end.
Using SysUtils variables
The SysUtils unit provides the Windows version information in several variables:
uses SysUtils;
begin
Writeln('Win32 Platform : ', Win32Platform );
Writeln('Win32 Major Version: ', Win32MajorVersion);
Writeln('Win32 Minor Version: ', Win32MinorVersion);
Writeln('Win32 Build Number : ', Win32BuildNumber );
Writeln('Win32 CSD Version : ', Win32CSDVersion );
Readln;
end.
The output looks like this for Windows 7 Service Pack 1:
Win32 Platform : 2 Win32 Major Version: 6 Win32 Minor Version: 1 Win32 Build Number : 7601 Win32 CSD Version : Service Pack 1
The output looks like this for Windows 10 Pro Build 18362 (64 bit):
Win32 Platform : 2 Win32 Major Version: 6 Win32 Minor Version: 2 Win32 Build Number : 9200 Win32 CSD Version :
The output will show Win32BuildNumber as 22000 or bigger for Windows 11.
Win32 Platform : 2 Win32 Major Version: 6 Win32 Minor Version: 2 Win32 Build Number : 22000 Win32 CSD Version :
Using Windows unit
The function below is intended for older OS versions. Please note that the GetVersion function is deprecated in Windows 8.1 and newer versions. More universal approach is using SysUtils unit variables, as shown above.
uses
Windows, SysUtils, ...;
{
Meaning of Windows version numbers:
5.0 => Windows 2000
5.1 => Windows XP
5.2 => Windows XP64 or Windows 2003 Server
6.0 => Windows Vista or Windows 2008 Server
6.1 => Windows 7 or Windows 2008 Server R2
6.2 => Windows 8 or Windows Server 2012
6.3 => Windows 8.1 or Windows Server 2012 RS
}
function WindowsVersionName: string;
begin
Result :=
IntToStr(LOBYTE(LOWORD(GetVersion))) + '.' +
IntToStr(HIBYTE(LOWORD(GetVersion)));
end;
References
- Windows Developer: Operating system version changes in Windows 8.1 and Windows Server 2012 R2. 05/31/2018