//取操作系统信息填充到结构
function GetOSVersionInfo(var Info: TOSVersionInfoEx): Boolean;
//windows系统类型 0表示取不到 1表示非服务器 2表示服务器
function GetWindowsSystemType: integer;
//取windows系统版本信息,主函数
function GetWindowsSystemVersion: string;
// 判断是否64位OS
function IsWin64: Boolean;
implementation
function IsWin64: Boolean;
var
Kernel32Handle: THandle;
IsWow64Process: function(Handle: Windows.THandle; var Res: Windows.BOOL): Windows.BOOL; stdcall;
GetNativeSystemInfo: procedure(var lpSystemInfo: TSystemInfo); stdcall;
isWoW64: Bool;
SystemInfo: TSystemInfo;
const
PROCESSOR_ARCHITECTURE_AMD64 = 9;
PROCESSOR_ARCHITECTURE_IA64 = 6;
begin
Kernel32Handle := GetModuleHandle('KERNEL32.DLL');
if Kernel32Handle = 0 then
Kernel32Handle := LoadLibrary('KERNEL32.DLL');
if Kernel32Handle <> 0 then
begin
IsWOW64Process := GetProcAddress(Kernel32Handle,'IsWow64Process');
GetNativeSystemInfo := GetProcAddress(Kernel32Handle,'GetNativeSystemInfo');
if Assigned(IsWow64Process) then
begin
IsWow64Process(GetCurrentProcess,isWoW64);
Result := isWoW64 and Assigned(GetNativeSystemInfo);
if Result then
begin
GetNativeSystemInfo(SystemInfo);
Result := (SystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) or
(SystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64);
end;
end
else Result := False;
end
else Result := False;
end;
function GetWindowsSystemType: integer;
var
info: TOSVersionInfoEx;
begin
result := 0;
if (GetOSVersionInfo(info) = false) then exit;
case info.wProductType of
VER_NT_WORKSTATION: Result:= 1; //非服务器
VER_NT_SERVER: Result:= 2; //服务器版
VER_NT_DOMAIN_CONTROLLER: Result:= 2; //域服务器
end;
end;
function GetWindowsSystemVersion: string;
var
info: TOSVersionInfoEx;
sysInfo: Tsysteminfo;
ARegistry : TRegistry;
begin
Result :='None';
windows.GetSystemInfo(sysInfo); //系统信息
try
if (GetOSVersionInfo(info) = false) then exit;
with info do begin
case dwMajorVersion of //主版本
3: if dwMinorVersion=51 then Result :='NT 3.51';
4: case dwMinorVersion of //次版本
0: case dwPlatformId of
VER_PLATFORM_WIN32_WINDOWS: if (szCSDVersion[1] ='B') or (szCSDVersion[1] ='C') then Result :='95 OSR2' else Result :='95';
VER_PLATFORM_WIN32_NT: case wProductType of
VER_NT_WORKSTATION: Result :='NT Workstation 4.0';
VER_NT_SERVER: if wSuiteMask = VER_SUITE_ENTERPRISE then Result :='NT Advanced Server 4.0' else Result :='NT Server 4.0';
end;
end;
1: if szCSDVersion[1] = 'A' then Result :='98 SE' else Result :='98';
9: Result :='Me';
end;
5: case dwMinorVersion of
0: case wProductType of
VER_NT_WORKSTATION: Result := '2000 Professional';
VER_NT_SERVER: if wSuiteMask and VER_SUITE_DATACENTER <> 0 then Result :='2000 Datacenter Server'
else if wSuiteMask and VER_SUITE_ENTERPRISE <> 0 then Result :='2000 Advanced Server'
else Result :='2000 Server';
end;
1: if wSuiteMask and VER_SUITE_PERSONAL <> 0 then Result :='XP Home Edition' else Result :='XP Professional';
2: begin
if GetSystemMetrics(SM_SERVERR2) = 0 then Result :='Server 2003' else Result :='Server 2003 R2';
if wSuiteMask and VER_SUITE_DATACENTER <>0 then Result :=Result +' Datacenter Edition'
else if wSuiteMask and VER_SUITE_ENTERPRISE <>0 then Result :=Result +' Enterprise Edition'
else if wSuiteMask and VER_SUITE_BLADE <>0 then Result :=Result +' Web Edition'
else if wSuiteMask = VER_SUITE_WH_SERVER then Result :='2003 Home Server'
else Result :=Result +' Standard Edition';
end;
end;
6: begin
case dwMinorVersion of
0: if wProductType = VER_NT_WORKSTATION then Result :='Vista' else Result :='Server 2008';
1: if wProductType = VER_NT_WORKSTATION then Result :='7' else Result :='Server 2008 R2';
2: if wProductType = VER_NT_WORKSTATION then Result :='8' else Result :='Server 8';
3: if wProductType = VER_NT_WORKSTATION then Result :='8.1' ;
end;
ARegistry := TRegistry.Create;
with ARegistry do
begin
RootKey :=HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion',false ) then Result :=Result+' '+ReadString('EditionID');
CloseKey;
Destroy;
end;
end;
end;
Result:='Windows '+Result;
if iswin64 then Result:=Result+' X64';
if dwMajorVersion>=5 then Result:=Result+' '+szCSDVersion;
end;
except
exit;
end;
end;
function GetOSVersionInfo(var Info: TOSVersionInfoEx): Boolean;
begin
FillChar(Info, SizeOf(TOSVersionInfoEx), 0);
Info.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx);
Result := GetVersionEx(TOSVersionInfo(Addr(Info)^));
if (not Result) then
Info.dwOSVersionInfoSize := 0;
end;
end.作者: chiannet 时间: 2013-9-13 14:13
最新的windows 8.1 应该也能识别作者: 2012peter2 时间: 2013-9-13 14:14 本帖最后由 2012peter2 于 2013-9-13 16:29 编辑
clonecd 发表于 2013-9-13 12:23
一种方法,启动后在CMD输入 ver 回车。