function IsWinNT: Boolean;
var
Version: TOSVERSIONINFO;
begin
result := False;
Version.dwOSVersionInfoSize := SizeOf(Version);
if GetVersionEx(Version) then
if Version.dwPlatformId = VER_PLATFORM_WIN32_NT then
result := True;
end;
function GetOSVersion: Integer;
var
Version: TOSVERSIONINFO;
begin
result := 0;
Version.dwOSVersionInfoSize := SizeOf(Version);
if GetVersionEx(Version) then
result := (Version.dwMajorVersion * 1000000) + (Version.dwMinorVersion * 10000) + Version.dwBuildNumber;
end;
function GetOSName: String;
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/sysinfo_3a0i.asp
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/sysinfo_1o1e.asp
// http://www.microsoft.com/japan/support/kb/articles/JP158/2/38.asp
// http://msdn.microsoft.com/library/en-us/sysinfo/base/getting_the_system_version.asp
// http://msdn.microsoft.com/library/en-us/sysinfo/base/getnativesysteminfo.asp
// http://technet2.microsoft.com/WindowsServer/ja/Library/efd0febb-02d9-4963-b0f4-b82be29aba921041.mspx?mfr=true
// http://msdn2.microsoft.com/en-us/library/ms724358.aspx
type
TOSVERSIONINFOEX =
packed record
dwOSVersionInfoSize:Cardinal;
dwMajorVersion :Cardinal;
dwMinorVersion :Cardinal;
dwBuildNumber :Cardinal;
dwPlatformId :Cardinal;
szCSDVersion :array [0..127] of Char;
wServicePackMajor :Word;
wServicePackMinor :Word;
wSuiteMask :Word;
wProductType :Byte;
wReserved :Byte;
end;
const
VER_NT_WORKSTATION = 1;
VER_NT_DOMAIN_CONTROLLER = 2;
VER_NT_SERVER = 3;
VER_SUITE_SMALLBUSINESS = $0001;
VER_SUITE_ENTERPRISE = $0002;
VER_SUITE_BACKOFFICE = $0004;
VER_SUITE_TERMINAL = $0010;
VER_SUITE_SMALLBUSINESS_RESTRICTED = $0020;
VER_SUITE_DATACENTER = $0080;
VER_SUITE_SINGLEUSERTS = $0100;
VER_SUITE_PERSONAL = $0200;
VER_SUITE_BLADE = $0400;
PROCESSOR_ARCHITECTURE_INTEL = 0;
PROCESSOR_ARCHITECTURE_MIPS = 1;
PROCESSOR_ARCHITECTURE_ALPHA = 2;
PROCESSOR_ARCHITECTURE_PPC = 3;
PROCESSOR_ARCHITECTURE_SHX = 4;
PROCESSOR_ARCHITECTURE_ARM = 5;
PROCESSOR_ARCHITECTURE_IA64 = 6;
PROCESSOR_ARCHITECTURE_ALPHA64 = 7;
PROCESSOR_ARCHITECTURE_MSIL = 8;
PROCESSOR_ARCHITECTURE_AMD64 = 9;
PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10;
SM_SERVERR2 = 80;
PRODUCT_UNDEFINED = $00000000;
PRODUCT_ULTIMATE = $00000001;
PRODUCT_HOME_BASIC = $00000002;
PRODUCT_HOME_PREMIUM = $00000003;
PRODUCT_ENTERPRISE = $00000004;
PRODUCT_HOME_BASIC_N = $00000005;
PRODUCT_BUSINESS = $00000006;
PRODUCT_STANDARD_SERVER = $00000007;
PRODUCT_DATACENTER_SERVER = $00000008;
PRODUCT_SMALLBUSINESS_SERVER = $00000009;
PRODUCT_ENTERPRISE_SERVER = $0000000A;
PRODUCT_STARTER = $0000000B;
PRODUCT_DATACENTER_SERVER_CORE = $0000000C;
PRODUCT_STANDARD_SERVER_CORE = $0000000D;
PRODUCT_ENTERPRISE_SERVER_CORE = $0000000E;
PRODUCT_ENTERPRISE_SERVER_IA64 = $0000000F;
PRODUCT_BUSINESS_N = $00000010;
PRODUCT_WEB_SERVER = $00000011;
PRODUCT_CLUSTER_SERVER = $00000012;
PRODUCT_HOME_SERVER = $00000013;
PRODUCT_STORAGE_EXPRESS_SERVER = $00000014;
PRODUCT_STORAGE_STANDARD_SERVER = $00000015;
PRODUCT_STORAGE_WORKGROUP_SERVER = $00000016;
PRODUCT_STORAGE_ENTERPRISE_SERVER = $00000017;
PRODUCT_SERVER_FOR_SMALLBUSINESS = $00000018;
PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = $00000019;
var
Unknown: Boolean;
SP, Dmy: String;
Version: TOSVERSIONINFO;
VersionEX: TOSVERSIONINFOEX;
SystemInfo: SYSTEM_INFO;
{StatusEx begin}
function StatusEx: TOSVERSIONINFOEX;
var
po: TFarProc;
DLLWnd: THandle;
VEX: TOSVERSIONINFOEX;
GetVersionEx2: function(var LPOSVERSIONINFO: TOSVERSIONINFOEX): Boolean; stdcall;
begin
po := nil;
DLLWnd := LoadLibrary('kernel32');
if DLLWnd > 0 then
begin
try
{$IFDEF UNICODE}
po := GetProcAddress(DLLWnd, 'GetVersionExW');
{$ELSE}
po := GetProcAddress(DLLWnd, 'GetVersionExA');
{$ENDIF}
if po <> nil then
begin
@GetVersionEx2 := po;
VEX.dwOSVersionInfoSize := SizeOf(VEX);
if GetVersionEx2(VEX) then
result := VEX;
end;
finally
FreeLibrary(DLLWnd);
end;
end;
end;
{StatusEx end}
{StatusEx2 begin}
function StatusEx2: SYSTEM_INFO;
var
po: TFarProc;
DLLWnd: THandle;
SI: SYSTEM_INFO;
GetNativeSystemInfo: procedure(var LPSYSTEM_INFO: SYSTEM_INFO); stdcall;
begin
po := nil;
DLLWnd := LoadLibrary('kernel32');
if DLLWnd > 0 then
begin
try
po := GetProcAddress(DLLWnd, 'GetNativeSystemInfo');
if po <> nil then
begin
@GetNativeSystemInfo := po;
GetNativeSystemInfo(SI);
result := SI;
end;
finally
FreeLibrary(DLLWnd);
end;
end;
end;
{StatusEx2 end}
{StatusEx3 begin}
function StatusEx3(OSMajor, OSMinor, SPMajor, SPMinor: DWORD): DWORD;
var
po: TFarProc;
DLLWnd: THandle;
PT: DWORD;
GetProductInfo: function(AOSMajor, AOSMinor, ASPMajor, ASPMinor: DWORD; var ProductType: DWORD): Boolean; stdcall;
begin
po := nil;
DLLWnd := LoadLibrary('kernel32');
if DLLWnd > 0 then
begin
try
po := GetProcAddress(DLLWnd, 'GetProductInfo');
if po <> nil then
begin
@GetProductInfo := po;
GetProductInfo(OSMajor, OSMinor, SPMajor, SPMinor, PT);
result := PT;
end;
finally
FreeLibrary(DLLWnd);
end;
end;
end;
{StatusEx3 end}
begin
result := '';
Version.dwOSVersionInfoSize := SizeOf(Version);
if GetVersionEx(Version) then
begin
Dmy := 'Windows';
SP := Trim(StrPas(Version.szCSDVersion));
case Version.dwPlatformId of
// Windows3.1(Win32s)
VER_PLATFORM_WIN32s:
Dmy := Dmy + Format('%d.%d(Win32s)',[Version.dwMajorVersion, Version.dwMinorVersion]);
// Windows9x系
VER_PLATFORM_WIN32_WINDOWS:
begin
case Version.dwMinorVersion of
// Windows95
00:begin
Dmy := Dmy + '95';
case LOWORD(Version.dwBuildNumber) of
1111:
Dmy := Dmy + ' OSR2';
1212..1213:
Dmy := Dmy + ' OSR2.1';
1214..9999:
Dmy := Dmy + ' OSR2.5';
end;
end;
// Windows98
10:begin
Dmy := Dmy + '98';
case LOWORD(Version.dwBuildNumber) of
2222..9999:
Dmy := Dmy + ' Second Edition';
end;
end;
// WindowsMe
90:Dmy := Dmy + 'Me';
end;
end;
// WindowsNT系
VER_PLATFORM_WIN32_NT:
begin
Unknown := False;
case Version.dwMajorVersion of
5:begin
VersionEx := StatusEx;
case Version.dwMinorVersion of
// 2000
0:begin
Dmy := Dmy + '2000 ';
case VersionEx.wProductType of
VER_NT_WORKSTATION:
Dmy := Dmy + 'Professional';
else
Dmy := Dmy + 'Server';
end;
end;
// XP
1:begin
case VersionEx.wProductType of
VER_NT_WORKSTATION:
begin
Dmy := Dmy + 'XP ';
if (VersionEx.wSuiteMask and VER_SUITE_PERSONAL) = VER_SUITE_PERSONAL then
Dmy := Dmy + 'Home Edition'
else
Dmy := Dmy + 'Professional';
end;
else
Dmy := Dmy + 'Server 2003';
end;
end;
// XP
2:begin
SystemInfo := StatusEx2;
case VersionEx.wProductType of
VER_NT_WORKSTATION:
begin
if SystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 then
Dmy := Dmy + 'XP Professional x64 Edition'
else
Unknown := True;
end;
VER_NT_SERVER,
VER_NT_DOMAIN_CONTROLLER:
begin
Dmy := Dmy + 'Server 2003 ';
if GetSystemMetrics(SM_SERVERR2) = 1 then
Dmy := Dmy + 'R2 ';
case SystemInfo.wProcessorArchitecture of
PROCESSOR_ARCHITECTURE_IA64:
begin
if (VersionEx.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
Dmy := Dmy + 'Datacenter Edition for Itanium-based Systems'
else if (VersionEx.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
Dmy := Dmy + 'Enterprise Edition for Itanium-based Systems'
else
Dmy := Dmy + 'Standard Edition for Itanium-based Systems';
end;
PROCESSOR_ARCHITECTURE_AMD64:
begin
if (VersionEx.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
Dmy := Dmy + 'Datacenter x64 Edition'
else if (VersionEx.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
Dmy := Dmy + 'Enterprise x64 Edition'
else
Dmy := Dmy + 'Standard x64 Edition';
end;
else
if (VersionEx.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
Dmy := Dmy + 'Datacenter Edition'
else if (VersionEx.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
Dmy := Dmy + 'Enterprise Edition'
else if (VersionEx.wSuiteMask and VER_SUITE_BLADE) = VER_SUITE_BLADE then
Dmy := Dmy + 'Web Edition'
else
Dmy := Dmy + 'Standard Edition';
end;
end;
else
Unknown := True;
end;
end;
else
Unknown := True;
end;
end;
6:begin
VersionEx := StatusEx;
case Version.dwMinorVersion of
0, 1:
begin
case VersionEx.wProductType of
VER_NT_WORKSTATION:
begin
case Version.dwMinorVersion of
0:Dmy := Dmy + ' Vista ';
1:Dmy := Dmy + ' 7 ';
end;
case StatusEx3(Version.dwMajorVersion, Version.dwMinorVersion, 0, 0) of
PRODUCT_ULTIMATE:
Dmy := Dmy + 'Ultimate';
PRODUCT_HOME_BASIC:
Dmy := Dmy + 'Home Basic';
PRODUCT_HOME_PREMIUM:
Dmy := Dmy + 'Home Premium';
PRODUCT_ENTERPRISE:
Dmy := Dmy + 'Business';
PRODUCT_HOME_BASIC_N:
Dmy := Dmy + 'Home Basic N';
PRODUCT_BUSINESS:
Dmy := Dmy + 'Business';
PRODUCT_STARTER:
Dmy := Dmy + 'Starter Edition';
PRODUCT_BUSINESS_N:
Dmy := Dmy + 'Business N';
end;
end;
else
case Version.dwMinorVersion of
0:Dmy := Dmy + 'Server 2008 ';
1:Dmy := Dmy + 'Server 2008 R2 ';
end;
case StatusEx3(Version.dwMajorVersion, Version.dwMinorVersion, 0, 0) of
PRODUCT_STANDARD_SERVER:
Dmy := Dmy + 'Standard Edition';
PRODUCT_DATACENTER_SERVER:
Dmy := Dmy + 'Datacenter Edition';
PRODUCT_SMALLBUSINESS_SERVER:
Dmy := Dmy + 'Small Business Server';
PRODUCT_ENTERPRISE_SERVER:
Dmy := Dmy + 'Enterprise Edition';
PRODUCT_DATACENTER_SERVER_CORE:
Dmy := Dmy + 'Datacenter Edition(Core)';
PRODUCT_STANDARD_SERVER_CORE:
Dmy := Dmy + 'Standard Edition(Core)';
PRODUCT_ENTERPRISE_SERVER_CORE:
Dmy := Dmy + 'Enterprise Edition(Core)';
PRODUCT_ENTERPRISE_SERVER_IA64:
Dmy := Dmy + 'Enterprise Edition for Itanium-based Systems';
PRODUCT_WEB_SERVER:
Dmy := Dmy + 'Web Server Edition';
PRODUCT_CLUSTER_SERVER:
Dmy := Dmy + 'Cluster Server Edition';
PRODUCT_HOME_SERVER:
Dmy := Dmy + 'Home Server Edition';
PRODUCT_STORAGE_EXPRESS_SERVER:
Dmy := Dmy + 'Storage Server Express Edition';
PRODUCT_STORAGE_STANDARD_SERVER:
Dmy := Dmy + 'Storage Server Standard Edition';
PRODUCT_STORAGE_WORKGROUP_SERVER:
Dmy := Dmy + 'Storage Server Workgroup Edition';
PRODUCT_STORAGE_ENTERPRISE_SERVER:
Dmy := Dmy + 'Storage Server Enterprise Edition';
PRODUCT_SERVER_FOR_SMALLBUSINESS:
Dmy := Dmy + 'for Small Business Edition';
PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
Dmy := Dmy + 'Small Business Server Premium Edition';
end;
end;
case SystemInfo.wProcessorArchitecture of
PROCESSOR_ARCHITECTURE_IA64:
Dmy := Dmy + '(IA64)';
PROCESSOR_ARCHITECTURE_AMD64:
Dmy := Dmy + '(x64)';
end;
end;
else
Unknown := True;
end;
end;
else
Unknown := True;
end;
if Unknown then
begin
Dmy := Dmy + Format('NT%d.%d ',[Version.dwMajorVersion, Version.dwMinorVersion]);
// NT4.0 SP6以降 or XP以降
if (Version.dwMajorVersion >= 5) or
((Version.dwMajorVersion = 4) and (Pos('6', SP) > 0)) then
begin
VersionEx := StatusEx;
case VersionEx.wProductType of
VER_NT_WORKSTATION:
Dmy := Dmy + 'WorkStation';
else
Dmy := Dmy + 'Server';
end;
end;
end;
end;
end;
if Length(SP) > 0 then
Dmy := Dmy + Format(' [%s]',[SP]);
end;
result := Dmy;
end;
|