Windows - descobrir a versao do windows do 311 ao 2003 |
Top Previous Next |
|
// Ultimate - Windows Detection Routines
uses Registry;
type TWindowsType = (winUnknown,win31,win95,win95OSR2,winNT,win98,win98se,winME,win2000,winXP,win2003); TWindowsProductType = (wptWorkstation, wptServer);
TWindowsProductKind = record AsString : String; AsType : TWindowsProductType; end;
TWindowsProductVersion = record AsString : String; Major : Integer; Minor : Integer; end;
TWindowsTypeEx = record Full : String; Product : String; Kind : TWindowsProductKind; OSKind : TWindowsType; OSVersion : TWindowsProductVersion; OSBuild : Integer; ServicePack : String; ServicePackVersion : TWindowsProductVersion; end;
function GetWindowsTypeEx : TWindowsTypeEx; const VER_NT_WORKSTATION : integer = $1; VER_NT_DOMAIN_CONTROLLER : integer = $2; VER_NT_SERVER : integer = $3; VER_WORKSTATION_NT : integer = $40000000;
VER_SUITE_SMALLBUSINESS : integer = $1; // Microsoft Small Business Server VER_SUITE_ENTERPRISE : integer = $2; // Win2k Adv Server or .Net Enterprise Server VER_SUITE_BACKOFFICE : integer = $4; // Microsoft Backoffice VER_SUITE_COMMUNICATIONS : integer = $8; VER_SUITE_TERMINAL : integer = $10; // Terminal Services is installed. VER_SUITE_SMALLBUSINESS_RESTRICTED : integer = $20; VER_SUITE_EMBEDDEDNT : integer = $40; VER_SUITE_DATACENTER : integer = $80; // Win2k Datacenter VER_SUITE_SINGLEUSERTS : integer = $100; // Terminal server in remote admin mode VER_SUITE_PERSONAL : integer = $200; VER_SUITE_BLADE : integer = $400; // Microsoft .Net webserver installed
type OSVERSIONINFOEX = packed record dwOSVersionInfoSize: DWORD; dwMajorVersion: DWORD; dwMinorVersion: DWORD; dwBuildNumber: DWORD; dwPlatformId: DWORD; szCSDVersion: Array [0..127 ] of Char; wServicePackMajor: WORD; wServicePackMinor: WORD; wSuiteMask: WORD; wProductType: BYTE; wReserved: BYTE; End; TOSVersionInfoEx = OSVERSIONINFOEX; POSVersionInfoEx = ^TOSVersionInfoEx;
var OSVI : TOSVersionInfoEx; OS : TOSVersionInfo; IsOSVIEx : boolean; pVer : POSVersionInfo; // old version!
r : TRegistry; ts : string; begin // Try calling GetVersionEx using the OSVERSIONINFOEX structure. // If that fails, try using the OSVERSIONINFO structure. ZeroMemory(@OSVI,SizeOf(OSVI)); osvi.dwOSVersionInfoSize := sizeof(OSVI); pVer := @OSVI; IsOSVIEx := GetVersionEx(pVer^);
if not IsOSVIEx then begin osvi.dwOSVersionInfoSize := sizeof(OS); if not GetVersionEx(pVer^) then Exit; end;
Result.OSVersion.AsString := Format('%d.%d',[OSVI.dwMajorVersion,OSVI.dwMinorVersion]); Result.OSVersion.Major := OSVI.dwMajorVersion; Result.OSVersion.Minor := OSVI.dwMinorVersion; Result.ServicePackVersion.AsString := Format('%d.%d',[OSVI.wServicePackMajor,OSVI.wServicePackMinor]); Result.ServicePackVersion.Major := OSVI.wServicePackMajor; Result.ServicePackVersion.Minor := OSVI.wServicePackMinor; Result.OSBuild := OSVI.dwBuildNumber;
case OSVI.dwPlatformId of // Test for the Windows NT product family. VER_PLATFORM_WIN32_NT: begin // Test for the specific product family. if (osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 2) then begin Result.Product := 'Microsoft Windows Server 2003 family'; Result.OSKind := win2003; end;
if (osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1) then begin Result.Product := 'Microsoft Windows XP'; Result.OSKind := winXP; end;
if (osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0) then begin Result.Product := 'Microsoft Windows 2000'; Result.OSKind := win2000; end;
if (osvi.dwMajorVersion <= 4) then begin Result.Product := 'Microsoft Windows NT'; Result.OSKind := winNT; end;
// Test for specific product on Windows NT 4.0 SP6 and later. if( IsOSVIEx ) then begin // Test for the workstation type. if ( osvi.wProductType = VER_NT_WORKSTATION ) then begin Result.Kind.AsType := wptWorkstation; if( osvi.dwMajorVersion = 4 ) then Result.Kind.AsString := 'Workstation 4.0' else if boolean(( osvi.wSuiteMask and VER_SUITE_PERSONAL )) then Result.Kind.AsString := 'Home Edition' else Result.Kind.AsString := 'Professional'; end else // Test for the server type. if (osvi.wProductType = VER_NT_SERVER) then begin Result.Kind.AsType := wptServer; // 2003 Server family if ( osvi.dwMajorVersion = 5 ) and ( osvi.dwMinorVersion = 2 ) then begin if boolean(( osvi.wSuiteMask and VER_SUITE_DATACENTER )) then Result.Kind.AsString := 'Datacenter Edition' else if( osvi.wSuiteMask and VER_SUITE_ENTERPRISE ) = 0 then Result.Kind.AsString := 'Enterprise Edition' else if ( osvi.wSuiteMask = VER_SUITE_BLADE ) then Result.Kind.AsString := 'Web Edition' else Result.Kind.AsString := 'Standard Edition' end else // 2000 Server family if (osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0) then begin Result.Product := 'Microsoft Windows Server 2000 family';
if boolean(( osvi.wSuiteMask and VER_SUITE_DATACENTER )) then Result.Kind.AsString := 'Datacenter Server' else if boolean((osvi.wSuiteMask and VER_SUITE_ENTERPRISE )) then Result.Kind.AsString := 'Advanced Server' else Result.Kind.AsString := 'Server'; end else // Windows NT 4.0 begin if boolean(( osvi.wSuiteMask and VER_SUITE_ENTERPRISE )) then Result.Kind.AsString := 'Server 4.0, Enterprise Edition' else Result.Kind.AsString := 'Server 4.0'; end; end; end else // Test for specific product on Windows NT 4.0 SP5 and earlier begin r := TRegistry.Create; r.RootKey := HKEY_LOCAL_MACHINE; r.OpenKey('SYSTEM\CurrentControlSet\Control\ProductOptions',False); ts := AnsiUpperCase(R.ReadString('ProductType')); r.Free; if ansisametext(ts,'WINNT') then Result.Kind.AsString := 'Workstation' else if ansisametext(ts,'SERVERNT') then Result.Kind.AsString := 'Server' else if ansisametext(ts,'LANMANNT') then Result.Kind.AsString := 'Advanced Server';
Result.Kind.AsString := Result.Kind.AsString + format(' %d.%d ',[osvi.dwMajorVersion, osvi.dwMinorVersion] ); end;
// Display service pack (if any) and build number. if (osvi.dwMajorVersion = 4) and ansisametext(osvi.szCSDVersion, 'Service Pack 6') then begin r := TRegistry.Create; r.RootKey := HKEY_LOCAL_MACHINE; // Test for SP6 versus SP6a. if r.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009',False) then Result.ServicePack := format('Service Pack 6a (Build %d) ' + #13#10, [osvi.dwBuildNumber and $FFFF]) else Result.ServicePack := format('%s (Build %d) ' + #13#10, [osvi.szCSDVersion, osvi.dwBuildNumber and $FFFF]); r.Free; end else // Windows NT 3.51 and earlier or Windows 2000 and later Result.ServicePack := format('%s (Build %d) ' + #13#10, [osvi.szCSDVersion, osvi.dwBuildNumber and $FFFF]);
Result.Full := format('%s %s',[Result.Product,Result.Kind.AsString]); end;
// Test for the Windows 95 product family. VER_PLATFORM_WIN32_WINDOWS : begin Result.Kind.AsType := wptWorkstation; Result.ServicePack := osvi.szCSDVersion; if (osvi.dwMajorVersion = 4 ) and ( osvi.dwMinorVersion = 0 ) then begin Result.Product := 'Microsoft Windows 95'; Result.OSKind := win95; if (osvi.szCSDVersion[1] = 'C') or (osvi.szCSDVersion[1] = 'B') then begin Result.Kind.AsString := 'OSR2'; Result.OSKind := win95OSR2; end; Result.Full := format('%s %s',[Result.Product,Result.Kind.AsString]); end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 10) then begin Result.Product := 'Microsoft Windows 98'; Result.OSKind := win98; if (osvi.szCSDVersion[1] = 'A') then begin Result.Kind.AsString := 'SE'; Result.OSKind := win98se; end;
Result.Full := format('%s %s',[Result.Product,Result.Kind.AsString]); end;
if (osvi.dwMajorVersion = 4) and (osvi.dwMinorVersion = 90) then begin Result.Product := 'Microsoft Windows Millennium Edition'; Result.Full := format('%s',[Result.Product]); Result.OSKind := winME; end; end;
VER_PLATFORM_WIN32s: begin Result.Product := 'Microsoft Win32s'; Result.Kind.AsType := wptWorkstation; Result.Full := format('%s',[Result.Product]); Result.OSKind := win31; end; end; Result.ServicePack := Trim(Result.ServicePack); end; |