2004-06-06 22:21:17 +00:00
|
|
|
{
|
|
|
|
:: X2UtOS provides a singleton OS object to access properties associated
|
|
|
|
:: with the Operating System, such as the version number.
|
|
|
|
:: It is part of the X2Utils suite.
|
|
|
|
::
|
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
2004-06-07 19:17:31 +00:00
|
|
|
:: Author: $Author$
|
2004-06-06 22:21:17 +00:00
|
|
|
}
|
|
|
|
unit X2UtOS;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Windows;
|
|
|
|
|
|
|
|
type
|
2014-12-31 09:36:39 +00:00
|
|
|
{$IF CompilerVersion < 23}
|
2010-01-31 11:18:49 +00:00
|
|
|
TOSVersionInfoEx = packed record
|
|
|
|
dwOSVersionInfoSize: DWORD;
|
|
|
|
dwMajorVersion: DWORD;
|
|
|
|
dwMinorVersion: DWORD;
|
|
|
|
dwBuildNumber: DWORD;
|
|
|
|
dwPlatformId: DWORD;
|
|
|
|
szCSDVersion: array[0..127] of AnsiChar;
|
|
|
|
wServicePackMajor: WORD;
|
|
|
|
wServicePackMinor: WORD;
|
|
|
|
wSuiteMask: WORD;
|
|
|
|
wProductType: Byte;
|
|
|
|
wReserved: Byte;
|
|
|
|
end;
|
2014-12-31 09:36:39 +00:00
|
|
|
{$IFEND}
|
2010-01-31 11:18:49 +00:00
|
|
|
|
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
//:$ Enumeration of the recognized Operating System versions
|
2004-07-22 08:20:11 +00:00
|
|
|
TX2OSVersion = (osWin95, osWin98, osWinME, osWinNT3, osWinNT4,
|
2010-01-31 11:18:49 +00:00
|
|
|
osWin2K, osWinXP, osWin2003, osWinVista, osWinServer2008,
|
2014-04-08 11:34:04 +00:00
|
|
|
osWinServer2008R2, osWin7, osWinServer2012, osWin8,
|
|
|
|
osWinServer2012R2, osWin81, osUnknown);
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2004-08-31 09:12:50 +00:00
|
|
|
//:$ Record to hold the Common Controls version
|
|
|
|
TX2CCVersion = record
|
|
|
|
Major: Cardinal;
|
|
|
|
Minor: Cardinal;
|
|
|
|
Build: Cardinal;
|
|
|
|
end;
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
{
|
|
|
|
:$ Contains extended version information for the Operating System
|
|
|
|
}
|
|
|
|
TX2OSVersionEx = class(TObject)
|
|
|
|
private
|
|
|
|
FName: String;
|
|
|
|
FVersionString: String;
|
|
|
|
FBuild: Cardinal;
|
2010-01-31 11:18:49 +00:00
|
|
|
FRawInfo: TOSVersionInfoEx;
|
2004-06-06 22:21:17 +00:00
|
|
|
public
|
|
|
|
//:$ Contains the name of the OS
|
2010-01-31 11:18:49 +00:00
|
|
|
property Name: String read FName write FName;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
|
|
|
//:$ Contains a string representation of the OS' version
|
2010-01-31 11:18:49 +00:00
|
|
|
property VersionString: String read FVersionString write FVersionString;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
|
|
|
//:$ Contains the build number of the OS
|
2010-01-31 11:18:49 +00:00
|
|
|
property Build: Cardinal read FBuild write FBuild;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
|
|
|
//:$ Contains the raw version information as provided by the OS
|
2010-01-31 11:18:49 +00:00
|
|
|
property RawInfo: TOSVersionInfoEx read FRawInfo write FRawInfo;
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Container for the Operating System's information
|
|
|
|
}
|
|
|
|
TX2OS = class(TObject)
|
|
|
|
private
|
2004-08-31 09:12:50 +00:00
|
|
|
FCCVersion: TX2CCVersion;
|
2004-06-06 22:21:17 +00:00
|
|
|
FVersion: TX2OSVersion;
|
|
|
|
FVersionEx: TX2OSVersionEx;
|
2004-08-31 09:12:50 +00:00
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
function GetSupportsUAC: Boolean;
|
|
|
|
function GetXPManifest: Boolean;
|
2004-06-06 22:21:17 +00:00
|
|
|
protected
|
2010-01-31 11:18:49 +00:00
|
|
|
procedure GetVersion; virtual;
|
|
|
|
procedure GetCCVersion; virtual;
|
2004-06-06 22:21:17 +00:00
|
|
|
public
|
2010-01-31 11:18:49 +00:00
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2004-06-07 10:27:08 +00:00
|
|
|
//:$ Returns the formatted version information
|
|
|
|
//:: If Build is False, the return value will not include the
|
|
|
|
//:: OS' Build number.
|
|
|
|
function FormatVersion(Build: Boolean = True): String;
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
|
2004-08-31 09:12:50 +00:00
|
|
|
//:$ Contains the Common Controls version
|
|
|
|
property ComCtlVersion: TX2CCVersion read FCCVersion;
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
//:$ Checks if the OS supports User Account Control
|
|
|
|
property SupportsUAC: Boolean read GetSupportsUAC;
|
|
|
|
|
2004-08-31 09:12:50 +00:00
|
|
|
//:$ Checks if the application uses an XP manifest
|
|
|
|
//:: If present, Common Controls version 6 or higher is available.
|
|
|
|
property XPManifest: Boolean read GetXPManifest;
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
//:$ Contains the detected OS version
|
|
|
|
property Version: TX2OSVersion read FVersion;
|
|
|
|
|
|
|
|
//:$ Contains extended OS version information
|
|
|
|
property VersionEx: TX2OSVersionEx read FVersionEx;
|
|
|
|
end;
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
function OS: TX2OS;
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
const
|
|
|
|
{ NT Product types: used by dwProductType field }
|
|
|
|
VER_NT_WORKSTATION = $0000001;
|
|
|
|
VER_NT_DOMAIN_CONTROLLER = $0000002;
|
|
|
|
VER_NT_SERVER = $0000003;
|
|
|
|
|
|
|
|
{ NT product suite mask values: used by wSuiteMask field }
|
|
|
|
VER_SUITE_SMALLBUSINESS = $00000001;
|
|
|
|
VER_SUITE_ENTERPRISE = $00000002;
|
|
|
|
VER_SUITE_BACKOFFICE = $00000004;
|
|
|
|
VER_SUITE_COMMUNICATIONS = $00000008;
|
|
|
|
VER_SUITE_TERMINAL = $00000010;
|
|
|
|
VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020;
|
|
|
|
VER_SUITE_EMBEDDEDNT = $00000040;
|
|
|
|
VER_SUITE_DATACENTER = $00000080;
|
|
|
|
VER_SUITE_SINGLEUSERTS = $00000100;
|
|
|
|
VER_SUITE_PERSONAL = $00000200;
|
|
|
|
VER_SUITE_SERVERAPPLIANCE = $00000400;
|
|
|
|
VER_SUITE_BLADE = VER_SUITE_SERVERAPPLIANCE;
|
|
|
|
|
2014-04-08 11:34:04 +00:00
|
|
|
|
2014-04-08 14:38:16 +00:00
|
|
|
X2OSVersionString: array[TX2OSVersion] of string =
|
2014-04-08 11:34:04 +00:00
|
|
|
(
|
|
|
|
'95', '98', 'ME', 'NT 3.51', 'NT 4',
|
2014-04-08 14:38:16 +00:00
|
|
|
'2000', 'XP', 'Server 2003', 'Vista', 'Server 2008',
|
2014-04-08 11:34:04 +00:00
|
|
|
'Server 2008 R2', '7', 'Server 2012', '8',
|
|
|
|
'Server 2012 R2', '8.1', 'Onbekend'
|
|
|
|
);
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
SysUtils;
|
2004-08-31 09:12:50 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
ComCtl32 = 'comctl32.dll';
|
|
|
|
|
|
|
|
type
|
|
|
|
PDllVersionInfo = ^TDllVersionInfo;
|
|
|
|
TDllVersionInfo = record
|
|
|
|
cbSize: DWORD;
|
|
|
|
dwMajorVersion: DWORD;
|
|
|
|
dwMinorVersion: DWORD;
|
|
|
|
dwBuildNumber: DWORD;
|
|
|
|
dwPlatformID: DWORD;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TDllGetVersion = function(pdvi: PDllVersionInfo): HRESULT; stdcall;
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
var
|
|
|
|
GOS: TX2OS;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
Singleton
|
|
|
|
========================================}
|
|
|
|
function OS;
|
|
|
|
begin
|
|
|
|
if not Assigned(GOS) then
|
2010-01-31 11:18:49 +00:00
|
|
|
GOS := TX2OS.Create;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
|
|
|
Result := GOS;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{================================== TX2OS
|
|
|
|
Initialization
|
|
|
|
========================================}
|
|
|
|
constructor TX2OS.Create;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersionEx := TX2OSVersionEx.Create;
|
|
|
|
GetVersion;
|
|
|
|
GetCCVersion;
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2OS.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FVersionEx);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{================================== TX2OS
|
|
|
|
Version
|
|
|
|
========================================}
|
|
|
|
procedure TX2OS.GetVersion;
|
|
|
|
var
|
2010-01-31 11:18:49 +00:00
|
|
|
versionInfo: TOSVersionInfoEx;
|
|
|
|
versionInfoPtr: POSVersionInfo;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
FVersion := osUnknown;
|
|
|
|
|
2008-01-20 14:50:26 +00:00
|
|
|
{ Get version information }
|
2010-01-31 11:18:49 +00:00
|
|
|
FillChar(versionInfo, SizeOf(versionInfo), 0);
|
|
|
|
versionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx);
|
|
|
|
|
|
|
|
versionInfoPtr := @versionInfo;
|
|
|
|
|
|
|
|
if not GetVersionEx(versionInfoPtr^) then
|
|
|
|
begin
|
|
|
|
{ Maybe this is an older Windows version, not supporting the Ex fields }
|
|
|
|
versionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
|
|
|
|
if not GetVersionEx(versionInfoPtr^) then
|
|
|
|
RaiseLastOSError;
|
|
|
|
end;
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2008-01-20 14:50:26 +00:00
|
|
|
with FVersionEx do
|
|
|
|
begin
|
|
|
|
{ No Kylix support yet, sorry! }
|
2010-01-31 11:18:49 +00:00
|
|
|
RawInfo := versionInfo;
|
2004-06-06 22:21:17 +00:00
|
|
|
Name := 'Windows';
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
case versionInfo.dwMajorVersion of
|
2008-01-20 14:50:26 +00:00
|
|
|
3: { Windows NT 3.51 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWinNT3;
|
2008-01-20 14:50:26 +00:00
|
|
|
4: { Windows 95/98/ME/NT 4 }
|
2010-01-31 11:18:49 +00:00
|
|
|
case versionInfo.dwMinorVersion of
|
2008-01-20 14:50:26 +00:00
|
|
|
0: { Windows 95/NT 4 }
|
2010-01-31 11:18:49 +00:00
|
|
|
case versionInfo.dwPlatformId of
|
2008-01-20 14:50:26 +00:00
|
|
|
VER_PLATFORM_WIN32_NT: { Windows NT 4 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWinNT4;
|
2008-01-20 14:50:26 +00:00
|
|
|
VER_PLATFORM_WIN32_WINDOWS: { Windows 95 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWin95;
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
2008-01-20 14:50:26 +00:00
|
|
|
10: { Windows 98 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWin98;
|
2008-01-20 14:50:26 +00:00
|
|
|
90: { Windows ME }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWinME;
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
2008-01-20 14:50:26 +00:00
|
|
|
5: { Windows 2000/XP/2003 }
|
2010-01-31 11:18:49 +00:00
|
|
|
case versionInfo.dwMinorVersion of
|
2008-01-20 14:50:26 +00:00
|
|
|
0: { Windows 2000 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWin2K;
|
2008-01-20 14:50:26 +00:00
|
|
|
1: { Windows XP }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWinXP;
|
2008-01-20 14:50:26 +00:00
|
|
|
2: { Windows Server 2003 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWin2003;
|
|
|
|
end;
|
2014-04-08 11:34:04 +00:00
|
|
|
6: { Windows Vista/Server 2008/7/2012/8 }
|
2010-01-31 11:18:49 +00:00
|
|
|
if versionInfo.wProductType = VER_NT_WORKSTATION then
|
|
|
|
begin
|
|
|
|
case versionInfo.dwMinorVersion of
|
|
|
|
0: { Windows Vista }
|
|
|
|
FVersion := osWinVista;
|
|
|
|
1: { Windows 7 }
|
|
|
|
FVersion := osWin7;
|
2014-04-08 11:34:04 +00:00
|
|
|
2: { Windows 8 }
|
|
|
|
FVersion := osWin8;
|
|
|
|
3: { Windows 8.1 }
|
|
|
|
FVersion := osWin81;
|
2010-01-31 11:18:49 +00:00
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
case versionInfo.dwMinorVersion of
|
2014-04-08 14:38:16 +00:00
|
|
|
0: { Windows Server 2008 }
|
2010-01-31 11:18:49 +00:00
|
|
|
FVersion := osWinServer2008;
|
2014-04-08 11:34:04 +00:00
|
|
|
1: { Windows Server 2008 R2 }
|
|
|
|
FVersion := osWinServer2008R2;
|
|
|
|
2: { Windows Server 2012 }
|
|
|
|
FVersion := osWinServer2012;
|
|
|
|
3: { Windows Server 2012 R2 }
|
|
|
|
FVersion := osWinServer2012R2;
|
2010-01-31 11:18:49 +00:00
|
|
|
end;
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-04-08 11:34:04 +00:00
|
|
|
if Version <> osUnknown then
|
2014-05-27 14:07:35 +00:00
|
|
|
VersionString := X2OSVersionString[Version]
|
2010-01-31 11:18:49 +00:00
|
|
|
else
|
2014-04-08 11:34:04 +00:00
|
|
|
VersionString := Format('%d.%d', [versionInfo.dwMajorVersion,
|
|
|
|
versionInfo.dwMinorVersion]);
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
if StrLen(versionInfo.szCSDVersion) > 0 then
|
2013-04-09 14:48:41 +00:00
|
|
|
VersionString := VersionString + ' ' + string(versionInfo.szCSDVersion);
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
case versionInfo.dwPlatformId of
|
2004-06-06 22:21:17 +00:00
|
|
|
VER_PLATFORM_WIN32_NT:
|
2010-01-31 11:18:49 +00:00
|
|
|
Build := versionInfo.dwBuildNumber;
|
2004-06-06 22:21:17 +00:00
|
|
|
VER_PLATFORM_WIN32_WINDOWS:
|
2010-01-31 11:18:49 +00:00
|
|
|
Build := LoWord(versionInfo.dwBuildNumber);
|
2004-06-06 22:21:17 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2004-08-31 09:12:50 +00:00
|
|
|
procedure TX2OS.GetCCVersion;
|
|
|
|
var
|
|
|
|
DllGetVersion: TDllGetVersion;
|
|
|
|
hLib: THandle;
|
|
|
|
viVersion: TDllVersionInfo;
|
|
|
|
|
|
|
|
begin
|
|
|
|
FillChar(FCCVersion, SizeOf(FCCVersion), #0);
|
|
|
|
hLib := LoadLibrary(ComCtl32);
|
|
|
|
|
|
|
|
if hLib <> 0 then
|
|
|
|
begin
|
|
|
|
@DllGetVersion := GetProcAddress(hLib, 'DllGetVersion');
|
|
|
|
if Assigned(DllGetVersion) then
|
|
|
|
begin
|
|
|
|
FillChar(viVersion, SizeOf(viVersion), #0);
|
|
|
|
viVersion.cbSize := SizeOf(viVersion);
|
2010-01-31 11:18:49 +00:00
|
|
|
|
2004-08-31 09:12:50 +00:00
|
|
|
DllGetVersion(@viVersion);
|
|
|
|
|
|
|
|
with FCCVersion do
|
|
|
|
begin
|
|
|
|
Major := viVersion.dwMajorVersion;
|
|
|
|
Minor := viVersion.dwMinorVersion;
|
|
|
|
Build := viVersion.dwBuildNumber;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
FreeLibrary(hLib);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
|
2004-06-07 10:27:08 +00:00
|
|
|
function TX2OS.FormatVersion;
|
|
|
|
var
|
|
|
|
sBuild: String;
|
|
|
|
|
|
|
|
begin
|
2010-01-31 11:18:49 +00:00
|
|
|
sBuild := '';
|
2004-06-07 10:27:08 +00:00
|
|
|
|
|
|
|
if Build then
|
2010-01-31 11:18:49 +00:00
|
|
|
sBuild := Format(' build %d', [FVersionEx.Build]);
|
2004-06-07 10:27:08 +00:00
|
|
|
|
|
|
|
with FVersionEx do
|
|
|
|
Result := Format('%s %s%s', [Name, VersionString, sBuild]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-01-31 11:18:49 +00:00
|
|
|
function TX2OS.GetXPManifest;
|
|
|
|
begin
|
|
|
|
Result := (FCCVersion.Major >= 6);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2OS.GetSupportsUAC: Boolean;
|
|
|
|
begin
|
|
|
|
Result := (FVersionEx.RawInfo.dwMajorVersion >= 6);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
initialization
|
|
|
|
finalization
|
|
|
|
FreeAndNil(GOS);
|
2004-08-31 09:12:50 +00:00
|
|
|
|
2004-06-06 22:21:17 +00:00
|
|
|
end.
|