获取操作系统类型/版本以及是否是64位的函数

//以下代码均来自网络

 

function GetWindowsVersionString: AnsiString;
var
  VI: TOSVersionInfoA;
begin
  VI.dwOSVersionInfoSize := SizeOf(TOSVersionInfoA);
  if GetVersionExA(VI) then
    with VI do
      Result := Trim(
        Format(
        '%d.%d build %d %s',
        [dwMajorVersion, dwMinorVersion, dwBuildNumber, szCSDVersion]
        )
        )
  else
    Result := '';
end;




function GetWindowsVersion: string; //读取操作系统版本
var
  AWin32Version: Extended;
  os: string;
begin
  os := 'Windows ';
  AWin32Version := StrtoFloat(format('%d.%d', [Win32MajorVersion, Win32MinorVersion]));
  if Win32Platform = VER_PLATFORM_WIN32s then
    Result := os + '32'
  else if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  begin
    if AWin32Version = 4.0 then
      Result := os + '95'
    else if AWin32Version = 4.1 then
      Result := os + '98'
    else if AWin32Version = 4.9 then
      Result := os + 'Me'
    else
      Result := os + '9x'
  end
  else if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    if AWin32Version = 3.51 then
      Result := os + 'NT 3.51'
    else if AWin32Version = 4.0 then
      Result := os + 'NT 4.0'
    else if AWin32Version = 5.0 then
      Result := os + '2000'
    else if AWin32Version = 5.1 then
      Result := os + 'XP'
    else if AWin32Version = 5.2 then
      Result := os + '2003'
    else if AWin32Version = 6.0 then
      Result := os + 'Vista'
    else if AWin32Version = 6.1 then
      Result := os + '7'
    else
      Result := os;
  end
  else
    Result := os + '??';
  Result := Result + ' ' + GetWIndowsVersionString;
end;

 

 

 

 

//判断操作是否是64位:

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;

posted @ 2012-03-10 00:18  Handll  阅读(689)  评论(0编辑  收藏  举报