| 
 | 
 
 
发表于 2013-9-13 14:12:01
|
显示全部楼层
 
 
 
 本帖最后由 chiannet 于 2013-9-13 14:13 编辑  
 
unit WindowsSysVersion; 
interface 
uses 
  Registry, windows  ; 
{$IFDEF CONDITIONALEXPRESSIONS} 
{$IF Defined(TOSVersionInfoEx)} 
{$DEFINE TOSVERSIONINFOEX_DEFINED} 
{$IFEND} 
{$ENDIF} 
{$IFNDEF TOSVERSIONINFOEX_DEFINED} 
type 
  POSVersionInfoEx = ^TOSVersionInfoEx; 
  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; 
 
const 
  VER_SERVER_NT = $80000000; 
{$EXTERNALSYM VER_SERVER_NT} 
  VER_WORKSTATION_NT = $40000000; 
{$EXTERNALSYM VER_WORKSTATION_NT} 
  VER_SUITE_SMALLBUSINESS = $00000001; 
{$EXTERNALSYM VER_SUITE_SMALLBUSINESS} 
  VER_SUITE_ENTERPRISE = $00000002; 
{$EXTERNALSYM VER_SUITE_ENTERPRISE} 
  VER_SUITE_BACKOFFICE = $00000004; 
{$EXTERNALSYM VER_SUITE_BACKOFFICE} 
  VER_SUITE_COMMUNICATIONS = $00000008; 
{$EXTERNALSYM VER_SUITE_COMMUNICATIONS} 
  VER_SUITE_TERMINAL = $00000010; 
{$EXTERNALSYM VER_SUITE_TERMINAL} 
  VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020; 
{$EXTERNALSYM VER_SUITE_SMALLBUSINESS_RESTRICTED} 
  VER_SUITE_EMBEDDEDNT = $00000040; 
{$EXTERNALSYM VER_SUITE_EMBEDDEDNT} 
  VER_SUITE_DATACENTER = $00000080; 
{$EXTERNALSYM VER_SUITE_DATACENTER} 
  VER_SUITE_SINGLEUSERTS = $00000100; 
{$EXTERNALSYM VER_SUITE_SINGLEUSERTS} 
  VER_SUITE_PERSONAL = $00000200; 
{$EXTERNALSYM VER_SUITE_PERSONAL} 
  VER_SUITE_BLADE = $00000400; 
{$EXTERNALSYM VER_SUITE_BLADE} 
  VER_SUITE_EMBEDDED_RESTRICTED = $00000800; 
{$EXTERNALSYM VER_SUITE_EMBEDDED_RESTRICTED} 
  VER_SUITE_SECURITY_APPLIANCE = $00001000; 
{$EXTERNALSYM VER_SUITE_SECURITY_APPLIANCE} 
  VER_SUITE_WH_SERVER = $00008000; 
{$EXTERNALSYM VER_SUITE_WH_SERVER} 
  PROCESSOR_ARCHITECTURE_AMD64 = 9; 
{$EXTERNALSYM PROCESSOR_ARCHITECTURE_AMD64} 
  SM_SERVERR2 = 89; 
{$EXTERNALSYM SM_SERVERR2} 
const 
  VER_NT_WORKSTATION = $0000001; 
{$EXTERNALSYM VER_NT_WORKSTATION} 
  VER_NT_DOMAIN_CONTROLLER = $0000002; 
{$EXTERNALSYM VER_NT_DOMAIN_CONTROLLER} 
  VER_NT_SERVER = $0000003; 
{$EXTERNALSYM VER_NT_SERVER} 
 
{$ENDIF} // TOSVERSIONINFOEX_DEFINED 
 
 
//取操作系统信息填充到结构 
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. |   
 
 
 
 |