Re: windows version in .h files

Florent Ouchet <[email protected]> Mon, 06 Feb 2006 13:06:36 +0100
Newsgroups gmane.comp.lang.delphi.jedi
Message-ID <[email protected]>
Hi,

The function GetWindowsVersion in JclSysInfo.pas does this detection. It 
is part of the Jedi Code Library (http://jcl.sourceforge.net) and it can 
easily be translated to C.

Best regards,

Florent Ouchet

function GetWindowsVersion: TWindowsVersion;
var
  TrimmedWin32CSDVersion: string;
  SystemInfo: TSystemInfo;
  OSVersionInfoEx: TOSVersionInfoEx;
const
  SM_SERVERR2 = 89;
begin
  Result := wvUnknown;
  TrimmedWin32CSDVersion := Trim(Win32CSDVersion);
  case Win32Platform of
    VER_PLATFORM_WIN32_WINDOWS:
      case Win32MinorVersion of
        0..9:
          if (TrimmedWin32CSDVersion = 'B') or (TrimmedWin32CSDVersion = 
'C') then
            Result := wvWin95OSR2
          else
            Result := wvWin95;
        10..89:
          // On Windows ME Win32MinorVersion can be 10 (indicating 
Windows 98
          // under certain circumstances (image name is setup.exe). Checking
          // the kernel version is one way of working around that.
          if KernelVersionHi = $0004005A then // 4.90.x.x
            Result := wvWinME
          else
          if TrimmedWin32CSDVersion = 'A' then
            Result := wvWin98SE
          else
            Result := wvWin98;
        90:
          Result := wvWinME;
      end;
    VER_PLATFORM_WIN32_NT:
      case Win32MajorVersion of
        3:
          case Win32MinorVersion of
            1:
              Result := wvWinNT31;
            5:
              Result := wvWinNT35;
            51:
              Result := wvWinNT351;
          end;
        4:
          Result := wvWinNT4;
        5:
          case Win32MinorVersion of
            0:
              Result := wvWin2000;
            1:
              Result := wvWinXP;
            2:
              begin
                OSVersionInfoEx.dwOSVersionInfoSize := 
SizeOf(OSVersionInfoEx);
                GetNativeSystemInfo(SystemInfo);
                if GetSystemMetrics(SM_SERVERR2) <> 0 then
                  Result := wvWin2003R2
                else if (SystemInfo.wProcessorArchitecture <> 
PROCESSOR_ARCHITECTURE_INTEL)
                  and GetVersionEx(OSVersionInfoEx) and 
(OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
                  Result := wvWinXP64
                else
                  Result := wvWin2003;
              end;
          end;
        6:
          if Win32MinorVersion = 0 then
          begin
            OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
            if GetVersionEx(OSVersionInfoEx) and 
(OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
              Result := wvWinVista
            else
              Result := wvWinLonghorn;
          end;
      end;
  end;
end;




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/Delphi-JEDI/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/