Difference between revisions of "Windows version"

From Free Pascal wiki
Jump to navigationJump to search
(Deleted categories outside of template for prevent copying to translations)
m (Alextpp moved page WindowsVersion to Windows version: why the page was named after one of variables, WindowsVersion?)
 
(11 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
  
This article is about Windows programming.
+
This article is about Windows programming. Obtaining information on the version of the running Windows instance is important for many purposes.
  
The function below determines the number of the current Windows version.
+
== Using Windows unit ==
 +
 
 +
The function below is intended for older versions. It determines the version of the current Windows installation. 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 below.
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
Line 22: Line 24:
 
}
 
}
  
function funGetWinVer: string;
+
function GetWinVersion: string;
// Returns the Windows version number as a string
 
 
begin
 
begin
   Result := IntToStr(LOBYTE(LOWORD(GetVersion)));
+
   Result :=  
  Result := Result + '.';
+
    IntToStr(LOBYTE(LOWORD(GetVersion))) + '.' +
  Result := Result + IntToStr(HIBYTE(LOWORD(GetVersion)));
+
    IntToStr(HIBYTE(LOWORD(GetVersion)));
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Alternatively, the [[SysUtils]] unit provides the Windows version information in variables:
+
== Using SysUtils variables ==
 +
 
 +
The SysUtils unit provides the Windows version information in several variables:
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
program EchoWinVersion;
+
uses SysUtils;
uses sysutils;
 
...
 
 
begin
 
begin
 
   Writeln('Win32 Platform    : ', Win32Platform    );
 
   Writeln('Win32 Platform    : ', Win32Platform    );
Line 43: Line 44:
 
   Writeln('Win32 Build Number : ', Win32BuildNumber );
 
   Writeln('Win32 Build Number : ', Win32BuildNumber );
 
   Writeln('Win32 CSD Version  : ', Win32CSDVersion  );
 
   Writeln('Win32 CSD Version  : ', Win32CSDVersion  );
   readln;
+
   Readln;
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 67: Line 68:
 
</pre>
 
</pre>
  
which is obviously wrong :( However, the following works for identifying Windows 10 (and before):
+
== Using Win32Proc Lazarus unit ==
 +
The following works for identifying Windows 11 and all older versions:
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
...
+
uses ..., Win32Proc;
Uses ..., Win32Proc;
 
...
 
  
Procedure GetWinVer;
+
function GetWinVersion: string;
Begin
+
begin
if WindowsVersion = wv95 then Memo.Lines.Add('Windows 95')
+
  case WindowsVersion of
  else if WindowsVersion = wvNT4 then Memo.Lines.Add('Windows NT v.4')
+
    wv95: Result:= 'Windows 95';
  else if WindowsVersion = wv98 then Memo.Lines.Add('Windows 98')
+
    wvNT4: Result:= 'Windows NT v.4';
  else if WindowsVersion = wvMe then Memo.Lines.Add('Windows ME')
+
    //etc.  
  else if WindowsVersion = wv2000 then Memo.Lines.Add('Windows 2000')
+
    //see possible values in the unit "win32proc" in "lcl/interfaces/win32/win32proc.pp"
  else if WindowsVersion = wvXP then Memo.Lines.Add('Windows XP')
+
   end;
  else if WindowsVersion = wvServer2003 then Memo.Lines.Add('Windows Server 2003/Windows XP64')
+
end.
  else if WindowsVersion = wvVista then Memo.Lines.Add('Windows Vista')
 
   else if WindowsVersion = wv7 then Memo.Lines.Add('Windows 7')
 
  else if WindowsVersion = wv10 then Memo.Lines.Add('Windows 10')
 
  else Memo.Lines.Add('Windows Unknown Version!');        
 
End.
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For Windows 10 64 bit this outputs "Windows 10".
+
== References ==
 +
 
 +
# Windows Developer: [https://docs.microsoft.com/en-us/windows/win32/w8cookbook/operating-system-version-changes-in-windows-8-1?redirectedfrom=MSDN Operating system version changes in Windows 8.1 and Windows Server 2012 R2]. 05/31/2018

Latest revision as of 12:58, 10 October 2023

Windows logo - 2012.svg

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 Windows unit

The function below is intended for older versions. It determines the version of the current Windows installation. 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 below.

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 GetWinVersion: string;
begin
  Result := 
    IntToStr(LOBYTE(LOWORD(GetVersion))) + '.' +
    IntToStr(HIBYTE(LOWORD(GetVersion)));
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  : 

Using Win32Proc Lazarus unit

The following works for identifying Windows 11 and all older versions:

uses ..., Win32Proc;

function GetWinVersion: string;
begin
  case WindowsVersion of
    wv95: Result:= 'Windows 95';
    wvNT4: Result:= 'Windows NT v.4';
    //etc. 
    //see possible values in the unit "win32proc" in "lcl/interfaces/win32/win32proc.pp"
  end;
end.

References

  1. Windows Developer: Operating system version changes in Windows 8.1 and Windows Server 2012 R2. 05/31/2018