星期二, 9月 04, 2012

判斷作業系統是否為Windows XP SP2+

//判斷作業系統是否為Windows XP SP2+
function IsXPSP2Above():boolean ;
var
  vi:   _OSVERSIONINFO;
begin
  Result:=False;
  FillChar(vi, SizeOf(vi), 0);
  vi.dwOSVersionInfoSize := SizeOf(vi);
  Windows.GetVersionEx(vi);

  // 作業系統
  if      (vi.dwMajorVersion=5) and (vi.dwMinorVersion = 1) and (Pos('Service Pack 2', AnsiString(vi.szCSDVersion)) > 0) then Result:=True  //Windows XP SP2
  else if (vi.dwMajorVersion=5) and (vi.dwMinorVersion = 1) and (Pos('Service Pack 3', AnsiString(vi.szCSDVersion)) > 0) then Result:=True  //Windows XP SP3
  else if (vi.dwMajorVersion=5) and (vi.dwMinorVersion = 2) then Result:=True  //Microsoft Windows Server 2003, Windows XP 64
  //(vi.dwMajorVersion=5) and (vi.dwMinorVersion = 0) Microsoft Windows 2000
  else if (vi.dwMajorVersion>5) then Result:=True;    //Vista+
end;