home *** CD-ROM | disk | FTP | other *** search
- (*-------------------------------OSWorks.pas----------------------------
- V1.0.235 - 05.03.2002 current release
- ------------------------------------------------------------------------*)
-
- unit OSWorks;
-
- interface
-
- uses Windows, SysUtils, Dialogs;
-
- type
- TOSVersionInfo = packed record
- dwOSVersionInfoSize,
- dwMajorVersion,
- dwMinorVersion,
- dwBuildNumber,
- dwPlatformId: DWord;
- szCSDVersion: array[0..127] of Char;
- end;
-
- POSVersionInfoEx = ^TOSVersionInfoEx;
- TOSVersionInfoEx = record
- dwOSVersionInfoSize: DWORD;
- dwMajorVersion: DWORD;
- dwMinorVersion: DWORD;
- dwBuildNumber: DWORD;
- dwPlatformId: DWORD;
- szCSDVersion: array[0..127] of Char;
- wServicePackMajor: Word;
- wServicePackMinor: Word;
- wSuiteMask: Word;
- wProductType: Byte;
- wReserved: Byte;
- end;
-
- TOSType = (OS_WIN95,
- OS_WIN98,
- OS_WINME,
- OS_NT351,
- OS_NT4_DOMAINCONTROLLER,
- OS_NT4_SERVER,
- OS_NT4_WORKSTATION,
- OS_WIN2000,
- OS_WIN2000_ADVSERVER,
- OS_WIN2000_DATACENTER,
- OS_WINXP_HOME,
- OS_WINXP_PROFESSIONAL,
- OS_WINXP_NETSERVER,
- OS_UNKNOWN);
-
- { Suite Mask Flag: NT4, 2000, XP }
- TOSSuiteType = (OSST_BACKOFFICE,
- OSST_DATACENTER,
- OSST_ENTERPRISE,
- OSST_PERSONAL {XP only},
- OSST_SMALLBUSINESS,
- OSST_SMALLBUSINESS_RESTRICTED,
- OSST_TERMINAL,
- OSST_UNKNOWN);
-
- { Product Type Flag: NT4, 2000, XP }
- TOSProductType = (OSPT_WORKSTATION,
- OSPT_DOMAIN_CONTROLLER,
- OSPT_SERVER,
- OSPT_UNKNOWN);
-
- function GetVersionEx(lpOs: pointer): BOOL; stdcall;
- external 'kernel32.dll' name 'GetVersionExA';
-
- procedure GetWindowsVersionEx(var OSVIE: TOSVersionInfoEx);
- function IsNTWorkstation: Boolean;
- function IsNTServer: Boolean;
- function IsDomainController: Boolean;
- function IsNTMachine: Boolean;
- function IsWin95: Boolean;
- function IsWin98: Boolean;
- function IsWinME: Boolean;
- function IsNT351: Boolean;
- function IsNT4: Boolean;
- function IsWin2K: Boolean;
- function IsWinXP: Boolean;
- function WinMajorVersion: Integer;
- function WinMinorVersion: Integer;
- function WinBuildNumber: Integer;
- function NTServicePackMajorVersion: Integer;
- function NTServicePackMinorVersion: Integer;
-
- function GetOS: TOSType;
- function GetOSName: String;
- function GetSuiteType: TOSSuiteType;
- function GetProductType: TOSProductType;
- function GetNTServicePackName: String;
-
- function Wow64IsRunning(AppHandle: THandle): Boolean;
-
- const
- VER_SUITE_BACKOFFICE = $00000004;
- VER_SUITE_DATACENTER = $00000080;
- VER_SUITE_ENTERPRISE = $00000002;
- VER_SUITE_PERSONAL = $00000200;
- VER_SUITE_SMALLBUSINESS = $00000001;
- VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020;
- VER_SUITE_TERMINAL = $00000010;
-
- VER_NT_WORKSTATION = $0000001;
- VER_NT_DOMAIN_CONTROLLER = $0000002;
- VER_NT_SERVER = $0000003;
-
- implementation
-
- procedure GetWindowsVersionEx(var OSVIE: TOSVersionInfoEx);
- var
- lpOS, lpOS2: POsVersionInfoEx;
- begin
- GetMem(lpOS, SizeOf(TOsVersionInfo));
- lpOs^.dwOSVersionInfoSize := SizeOf(TOsVersionInfo);
- while getVersionEx(lpOS) = false do
- begin
- GetMem(lpos2, lpos^.dwOSVersionInfoSize +1);
- lpOs2^.dwOSVersionInfoSize := lpOs^.dwOSVersionInfoSize +1;
- FreeMem(lpOs, lpOs^.dwOSVersionInfoSize);
- lpOS := lpOs2;
- end;
- OSVIE.dwMajorVersion := lpOs^.dwMajorVersion;
- OSVIE.dwMinorVersion := lpOs^.dwMinorVersion;
- OSVIE.dwBuildNumber := lpOS^.dwBuildNumber;
- OSVIE.dwPlatformId := lpOS^.dwPlatformId;
- OSVIE.szCSDVersion := lpOS^.szCSDVersion;
- OSVIE.wServicePackMajor := lpOS^.wServicePackMajor;
- OSVIE.wServicePackMinor := lpOS^.wServicePackMinor;
- OSVIE.wProductType := lpOS^.wProductType;
- OSVIE.wReserved := lpOS^.wReserved;
- FreeMem(lpOs, lpOs^.dwOSVersionInfoSize);
- end;
-
- function IsNTWorkstation: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION);
- end;
-
- function IsNTServer: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= (OSVersionInfoEx.wProductType = VER_NT_SERVER);
- end;
-
- function IsDomainController: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= (OSVersionInfoEx.wProductType = VER_NT_DOMAIN_CONTROLLER);
- end;
-
- function IsNTMachine: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT );
- end;
-
- function IsWin95: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS ) and
- ( OSVersionInfoEx.dwMajorVersion = 4 ) and
- ( OSVersionInfoEx.dwMinorVersion = 0 );
- end;
-
- function IsWin98: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS ) and
- ( OSVersionInfoEx.dwMajorVersion = 4 ) and
- ( OSVersionInfoEx.dwMinorVersion = 10 );
- end;
-
- function IsWinME: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS ) and
- ( OSVersionInfoEx.dwMajorVersion = 4 ) and
- ( OSVersionInfoEx.dwMinorVersion = 90 );
- end;
-
- function IsNT351: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT ) and
- ( OSVersionInfoEx.dwMajorVersion = 3 ) and
- ( OSVersionInfoEx.dwMinorVersion = 51 );
- end;
-
- function IsNT4: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT ) and
- ( OSVersionInfoEx.dwMajorVersion = 4 ) and
- ( OSVersionInfoEx.dwMinorVersion = 0 );
- end;
-
- function IsWin2K: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT ) and
- ( OSVersionInfoEx.dwMajorVersion = 5 ) and
- ( OSVersionInfoEx.dwMinorVersion = 0 );
- end;
-
- function IsWinXP: Boolean;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= ( OSVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT ) and
- ( OSVersionInfoEx.dwMajorVersion = 5 ) and
- ( OSVersionInfoEx.dwMinorVersion = 1 );
- end;
-
- function WinMajorVersion: Integer;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= OSVersionInfoEx.dwMajorVersion;
- end;
-
- function WinMinorVersion: Integer;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= OSVersionInfoEx.dwMinorVersion;
- end;
-
- function WinBuildNumber: Integer;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= OSVersionInfoEx.dwBuildNumber and $FFFF;
- end;
-
- function NTServicePackMajorVersion: Integer;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= OSVersionInfoEx.wServicePackMajor;
- end;
-
- function NTServicePackMinorVersion: Integer;
- var
- OSVersionInfoEx: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSVersionInfoEx);
- result:= OSVersionInfoEx.wServicePackMinor;
- end;
-
- function GetOS: TOSType;
- var
- OSV: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSV);
- result:= OS_UNKNOWN;
- if OSV.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
- case OSV.dwMinorVersion of
- 0: result:= OS_WIN95;
- 10: result:= OS_WIN98;
- 90: result:= OS_WINME;
- end
- else if OSV.dwPlatformId = VER_PLATFORM_WIN32_NT then
- case OSV.dwMajorVersion of
- 3: result:= OS_NT351;
- 4: case OSV.wProductType of
- VER_NT_DOMAIN_CONTROLLER:result:= OS_NT4_DOMAINCONTROLLER;
- VER_NT_SERVER: result:= OS_NT4_SERVER;
- VER_NT_WORKSTATION: result:= OS_NT4_WORKSTATION;
- end;
- 5: case OSV.dwMinorVersion of
- 0: case OSV.wSuiteMask of
- VER_SUITE_ENTERPRISE: result:= OS_WIN2000_ADVSERVER;
- VER_SUITE_DATACENTER: result:= OS_WIN2000_DATACENTER;
- else result:= OS_WIN2000;
- end;
- 1: case OSV.wSuiteMask of
- VER_SUITE_PERSONAL: result:= OS_WINXP_HOME;
- VER_SUITE_ENTERPRISE: result:= OS_WINXP_NETSERVER;
- else result:= OS_WINXP_PROFESSIONAL;
- end;
- end;
- end
- else begin
- result:= OS_UNKNOWN;
- end;
- end;
-
- function GetOSName: String;
- begin
- case GetOS of
- OS_WIN95: result:= 'Microsoft Windows 95';
- OS_WIN98: result:= 'Microsoft Windows 98';
- OS_WINME: result:= 'Microsoft Windows Millenium Edition';
- OS_NT351: result:= 'Microsoft Windows NT 3.51';
- OS_NT4_DOMAINCONTROLLER: result:= 'Microsoft Windows NT 4.0 Domain Controller';
- OS_NT4_SERVER: result:= 'Microsoft Windows NT 4.0 Server';
- OS_NT4_WORKSTATION: result:= 'Microsoft Windows NT 4.0 Workstation';
- OS_WIN2000: result:= 'Microsoft Windows 2000';
- OS_WIN2000_ADVSERVER: result:= 'Microsoft Windows 2000 Advanced Server';
- OS_WIN2000_DATACENTER: result:= 'Microsoft Windows 2000 DataCenter Server';
- OS_WINXP_HOME: result:= 'Microsoft Windows XP Home Edition';
- OS_WINXP_PROFESSIONAL: result:= 'Microsoft Windows XP Professional';
- OS_WINXP_NETSERVER: result:= 'Microsoft Windows XP .NET Server';
- OS_UNKNOWN: result:= 'MS OS unknown';
- end;
- end;
-
- function GetSuiteType: TOSSuiteType;
- var
- OSV: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSV);
- case OSV.wSuiteMask of
- VER_SUITE_BACKOFFICE: result:= OSST_BACKOFFICE;
- VER_SUITE_DATACENTER: result:= OSST_DATACENTER;
- VER_SUITE_ENTERPRISE: result:= OSST_ENTERPRISE;
- VER_SUITE_PERSONAL: {XP only} result:= OSST_PERSONAL;
- VER_SUITE_SMALLBUSINESS: result:= OSST_SMALLBUSINESS;
- VER_SUITE_SMALLBUSINESS_RESTRICTED: result:= OSST_SMALLBUSINESS_RESTRICTED;
- VER_SUITE_TERMINAL: result:= OSST_TERMINAL;
- else result:= OSST_UNKNOWN;
- end;
- end;
-
- function GetProductType: TOSProductType;
- var
- OSV: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSV);
- case OSV.wProductType of
- VER_NT_WORKSTATION: result:= OSPT_WORKSTATION;
- VER_NT_DOMAIN_CONTROLLER: result:= OSPT_DOMAIN_CONTROLLER;
- VER_NT_SERVER: result:= OSPT_SERVER;
- else result:= OSPT_UNKNOWN;
- end;
- end;
-
- function GetNTServicePackName: String;
- var
- OSV: TOSVersionInfoEx;
- begin
- GetWindowsVersionEx(OSV);
- result:= OSV.szCSDVersion;
- end;
-
- function Wow64IsRunning(AppHandle: THandle): Boolean;
- type
- TIsWow64Process = function(hProcess: THandle;
- Wow64Process: Boolean):Boolean; StdCall;
- const
- DLLName: PChar = 'Kernel32.dll';
- FcnName: PChar = 'IsWow64Process';
- var
- DLLHndl: THandle;
- IsWow64,
- bChkWow: Boolean;
- IsWow64Process: TIsWow64Process;
- begin
- result:= FALSE;
- IsWow64:= FALSE;
- bChkWow:= FALSE;
- DLLHndl:= LoadLibrary(DLLName);
- if (DLLHndl <> 0) then begin
- IsWow64Process:= GetProcAddress(DLLHndl, FcnName);
- if Assigned(IsWow64Process) then
- bChkWow:= IsWow64Process(AppHandle, IsWow64);
- result:= (bChkWow) and (IsWow64);
- end;
- FreeLibrary(DLLHndl);
- end;
-
- end.
-