Mirror

Windows detection routines (Views: 100)


Problem/Question/Abstract:

Here is how to find out almost everything of windows versions.

Answer:

function IsWin31: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  Result := (Os.dwPlatformId = VER_PLATFORM_WIN32s);
end;

function IsWin95: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion = 0) and (OS.dwPlatformId
    = VER_PLATFORM_WIN32_WINDOWS);
end;

function IsWin95OSR2: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion = 0) and
    (lo(OS.dwBuildNumber) > 1000) and (OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;

function IsWinNT: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := OS.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;

function IsWin98: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion > 0) and (OS.dwPlatformId
    = VER_PLATFORM_WIN32_WINDOWS);
end;

function IsWin98se: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion > 0) and
    (lo(OS.dwBuildNumber) > 2000) and (OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;

function IsWin2000: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 5) and (OS.dwPlatformId = VER_PLATFORM_WIN32_NT);
end;

function IsWinXP: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 5) and (OS.dwMinorVersion >= 1) and (OS.dwPlatformId
    = VER_PLATFORM_WIN32_NT);
end;

function IsWinMe: Boolean;
var
  OS: TOSVersionInfo;
begin
  ZeroMemory(@OS, SizeOf(OS));
  OS.dwOSVersionInfoSize := SizeOf(OS);
  GetVersionEx(OS);
  result := (OS.dwMajorVersion >= 4) and (OS.dwMinorVersion >= 90) and (OS.dwPlatformId
    = VER_PLATFORM_WIN32_WINDOWS);
end;

function GetNTType: string;
var
  r: TRegistry;
  ts: string;
begin

  Result := '[UNKNOWN]';

  if IsWinNT then
  begin
    r := TRegistry.Create;
    r.RootKey := HKEY_LOCAL_MACHINE;
    r.OpenKey('SYSTEM\CurrentControlSet\Control\ProductOptions', False);
    ts := AnsiUpperCase(R.ReadString('ProductType'));
    r.Free;
    if (ts = 'WINNT') then
    begin
      result := 'Workstation';
      if IsWin2000 then
        result := 'Professional';
    end
    else if (ts = 'SERVERNT') then
    begin
      result := 'Server';
    end
    else if (ts = 'LANMANNT') then
    begin
      result := 'Advanced Server';
    end;
  end;

end;

<< Back to main page