AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Windows-Version ermitteln

Ein Thema von Daniel B · begonnen am 19. Jul 2003 · letzter Beitrag vom 26. Feb 2005
Antwort Antwort
Daniel B
(Gast)

n/a Beiträge
 
#1

Windows-Version ermitteln

  Alt 19. Jul 2003, 22:22
Hallo,

hiermit kann man sich die Windowsversion anzeigen lassen, samt Service Packs usw..
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);

  function GetWinVer: String;
  var
    OsVinfo: TOSVERSIONINFO;
    TmpStr: array[0..255] of Char;
  begin
    ZeroMemory(@OsVinfo, SizeOf(OsVinfo));
    OsVinfo.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);
    if GetVersionEx(OsVinfo) then
    begin
      if OsVinfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
       begin
        if (OsVinfo.dwMajorVersion = 4) and (OsVinfo.dwMinorVersion > 0) then
        begin
          StrFmt(TmpStr, 'Windows 98 - Version %d.%.2d, Build %d, %s',
            [OsVinfo.dwMajorVersion, OsVinfo.dwMinorVersion,
             OsVinfo.dwBuildNumber and $FFFF, OSVinfo.szCSDVersion])
        end
        else
        begin
          StrFmt(TmpStr, 'Windows 95 - Version %d.%d, Build %d, %s',
            [OsVinfo.dwMajorVersion, OsVinfo.dwMinorVersion,
             OsVinfo.dwBuildNumber and $FFFF, OSVinfo.szCSDVersion]);
        end;
      end;
      if OsVinfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
      begin
        StrFmt(TmpStr, 'Microsoft Windows NT Version %d.%.2d, Build %d, %s',
          [OsVinfo.dwMajorVersion, OsVinfo.dwMinorVersion,
           OsVinfo.dwBuildNumber and $FFFF, OSVinfo.szCSDVersion]);
      end
    end
    else
    begin
      StrCopy(TmpStr, 'Fehler bei GetVersionEx()!');
    end;
    Result := TmpStr;
  end;

begin
  ShowMessage(GetWinVer);
end;
Grüsse, Daniel


Suchbegriffe: Windows Version

[edit=Matze]Suchbegriffe ergänzt. MfG, Matze[/edit]
  Mit Zitat antworten Zitat
MathiasSimmack
(Gast)

n/a Beiträge
 
#2

Re: Windows-Version ermitteln

  Alt 20. Jul 2003, 10:05
Das reicht aber nicht für ´ne Eins, Daniel. Was ist mit ME, 2000 oder XP. Oder Windows 2003? Ich habe mal folgendes aus dem PSDK abgeschrieben und für Delphi umgebaut:
Delphi-Quellcode:
//
// taken from PSDK Feb 2003 - "Getting the System version"
// (ms-help://MS.PSDK.1033/sysinfo/base/getting_the_system_version.htm)
//
function GetWinVersion: string;
var
  osvi : TOSVersionInfo;
  bOsVersionInfoEx : boolean;
  key : HKEY;
  szProductType : array[0..79]of char;
  dwBuflen : dword;
begin
  // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  // If that fails, try using the OSVERSIONINFO structure.
  ZeroMemory(@osvi,sizeof(TOSVersionInfo));
  osvi.dwOSVersionInfoSize := sizeof(TOSVersionInfo);

  bOsVersionInfoEx := GetVersionEx(osvi);
  if(not bOsVersionInfoEx) then begin
    osvi.dwOSVersionInfoSize := VERSIONINFOSIZE;

    if(not GetVersionEx(osvi)) then begin
      Result := 'Fehler bei der Ermittlung der Windows-Version';
      exit;
    end;
  end;

  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
          Result := 'Microsoft Windows Server 2003 family, ';

        if(osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 1) then
          Result := 'Microsoft Windows XP ';

        if(osvi.dwMajorVersion = 5) and (osvi.dwMinorVersion = 0) then
          Result := 'Microsoft Windows 2000 ';

        if(osvi.dwMajorVersion <= 4) then
          Result := 'Microsoft Windows NT ';

        // Test for specific product on Windows NT 4.0 SP6 and later.
        if(bOsVersionInfoEx) then begin
          // Test for the workstation type.
          if(osvi.wProductType = VER_NT_WORKSTATION) then begin
            if(osvi.dwMajorVersion = 4) then
              Result := Result + 'Workstation 4.0 '
            else if(osvi.wSuiteMask and VER_SUITE_PERSONAL <> 0) then
              Result := Result + 'Home Edition '
            else
              Result := Result + 'Professional ';
          end
          // Test for the server type.
          else if(osvi.wProductType = VER_NT_SERVER) then begin
            if(osvi.dwMajorVersion = 5) and
              (osvi.dwMinorVersion = 2) then
            begin // Win 2003
              if(osvi.wSuiteMask and VER_SUITE_DATACENTER <> 0) then
                Result := Result + 'Datacenter Edition '
              else if(osvi.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then
                Result := Result + 'Enterprise Edition '
              else if(osvi.wSuiteMask = VER_SUITE_BLADE) then
                Result := Result + 'Web Edition '
              else
                Result := Result + 'Standard Edition ';
            end // Win 2000
            else if(osvi.dwMajorVersion = 5) and
              (osvi.dwMinorVersion = 0) then
            begin
              if(osvi.wSuiteMask and VER_SUITE_DATACENTER <> 0) then
                Result := Result + 'Datacenter Server '
              else if(osvi.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then
                Result := Result + 'Advanced Server '
              else
                Result := Result + 'Server ';
            end
            else begin // Windows NT 4.0
              if(osvi.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then
                Result := Result + 'Server 4.0, Enterprise Edition '
              else
                Result := Result + 'Server 4.0 ';
            end;
          end
        end
        // Test for specific product on Windows NT 4.0 SP5 and earlier
        else begin
          dwBufLen := sizeof(szProductType);

          if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
            'SYSTEM\CurrentControlSet\Control\ProductOptions',0,
            KEY_QUERY_VALUE,key) = ERROR_SUCCESS) then
          try
            ZeroMemory(@szProductType,sizeof(szProductType));

            if(RegQueryValueEx(key,'ProductType',nil,nil,
              @szProductType,@dwBufLen) <> ERROR_SUCCESS) or
              (dwBufLen > sizeof(szProductType)) then
            ZeroMemory(@szProductType,sizeof(szProductType));
          finally
            RegCloseKey(key);
          end;

          if(lstrcmpi('WINNT',szProductType) = 0) then
            Result := Result + 'Workstation ';
          if(lstrcmpi('LANMANNT',szProductType) = 0) then
            Result := Result + 'Server ';
          if(lstrcmpi('SERVERNT',szProductType) = 0) then
            Result := Result + 'Advanced Server ';

          Result := Format('%s%d.%d',[Result,osvi.dwMajorVersion,
            osvi.dwMinorVersion]);
        end;

        // Display service pack (if any) and build number.
        if(osvi.dwMajorVersion = 4) and
          (lstrcmpi(osvi.szCSDVersion,'Service Pack 6') = 0) then
        begin
          // Test for SP6 versus SP6a.
          if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
            'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009',
            0,KEY_QUERY_VALUE,key) = ERROR_SUCCESS) then

            Result := Format('%sService Pack 6a (Build %d)',[Result,
              osvi.dwBuildNumber and $ffff])
          else
            // Windows NT 4.0 prior to SP6a
            Result := Format('%s%s (Build %d)',[Result,
              osvi.szCSDVersion,osvi.dwBuildNumber and $ffff]);
          RegCloseKey(key);
        end
        // Windows NT 3.51 and earlier or Windows 2000 and later
        else begin
          Result := Format('%s%s (Build %d)',[Result,
            osvi.szCSDVersion,osvi.dwBuildNumber and $ffff]);
        end;
      end;
    // Test for the Windows 95 product family.
    VER_PLATFORM_WIN32_WINDOWS:
      begin
        if(osvi.dwMajorVersion = 4) and
          (osvi.dwMinorVersion = 0) then
        begin
          Result := 'Microsoft Windows 95 ';
          if(osvi.szCSDVersion[0] = 'C') or
            (osvi.szCSDVersion[0] = 'B') then Result := Result + 'OSR2 ';
        end;

        if(osvi.dwMajorVersion = 4) and
          (osvi.dwMinorVersion = 10) then
        begin
          Result := 'Microsoft Windows 98 ';
          if(osvi.szCSDVersion[0] = 'A') then Result:= Result + 'SE ';
        end;

        if(osvi.dwMajorVersion = 4) and
          (osvi.dwMinorVersion = 90) then
        begin
          Result := 'Microsoft Windows Millennium Edition';
        end;
      end;
    VER_PLATFORM_WIN32s:
      Result := 'Microsoft Win32s';
  end;
end;
Wer (wie ich) noch Delphi 5 hat, bzw. bei wem der Compiler meckert, braucht noch das folgende. Es ist eine komplette Unit, damit man die originale Windows-Unit von Borland intakt lassen kann:
Delphi-Quellcode:
unit Windows_Fragment;

interface

uses
  Windows;

type
  POSVersionInfoA = ^TOSVersionInfoA;
  POSVersionInfoW = ^TOSVersionInfoW;
  POSVersionInfo = POSVersionInfoA;
  _OSVERSIONINFOA = record
    dwOSVersionInfoSize: DWORD;
    dwMajorVersion: DWORD;
    dwMinorVersion: DWORD;
    dwBuildNumber: DWORD;
    dwPlatformId: DWORD;
    szCSDVersion: array[0..127] of AnsiChar; { Maintenance string for PSS usage }
    wServicePackMajor,
    wServicePackMinor,
    wSuiteMask : word;
    wProductType,
    wReserved : byte;
  end;
  {$EXTERNALSYM _OSVERSIONINFOA}
  _OSVERSIONINFOW = record
    dwOSVersionInfoSize: DWORD;
    dwMajorVersion: DWORD;
    dwMinorVersion: DWORD;
    dwBuildNumber: DWORD;
    dwPlatformId: DWORD;
    szCSDVersion: array[0..127] of WideChar; { Maintenance string for PSS usage }
    wServicePackMajor,
    wServicePackMinor,
    wSuiteMask : word;
    wProductType,
    wReserved : byte;
  end;
  {$EXTERNALSYM _OSVERSIONINFOW}
  _OSVERSIONINFO = _OSVERSIONINFOA;
  TOSVersionInfoA = _OSVERSIONINFOA;
  TOSVersionInfoW = _OSVERSIONINFOW;
  TOSVersionInfo = TOSVersionInfoA;
  OSVERSIONINFOA = _OSVERSIONINFOA;
  {$EXTERNALSYM OSVERSIONINFOA}
  {$EXTERNALSYM OSVERSIONINFO}
  OSVERSIONINFOW = _OSVERSIONINFOW;
  {$EXTERNALSYM OSVERSIONINFOW}
  {$EXTERNALSYM OSVERSIONINFO}
  OSVERSIONINFO = OSVERSIONINFOA;

const
  {$EXTERNALSYM VERSIONINFOSIZEA}
  VERSIONINFOSIZEA = sizeof(TOSVersionInfoA) -
    (sizeof(word) * 3) - (sizeof(byte) * 2);
  {$EXTERNALSYM VERSIONINFOSIZEW}
  VERSIONINFOSIZEW = sizeof(TOSVersionInfoW) -
    (sizeof(word) * 3) - (sizeof(byte) * 2);
  {$EXTERNALSYM VERSIONINFOSIZE}
  VERSIONINFOSIZE = VERSIONINFOSIZEA;


const
  //
  // RtlVerifyVersionInfo() os product type values
  //
  VER_NT_WORKSTATION = $0000001;
  VER_NT_DOMAIN_CONTROLLER = $0000002;
  VER_NT_SERVER = $0000003;

  VER_SERVER_NT = $80000000;
  VER_WORKSTATION_NT = $40000000;
  VER_SUITE_SMALLBUSINESS = $00000001;
  VER_SUITE_ENTERPRISE = $00000002;
  VER_SUITE_BACKOFFICE = $00000004;
  VER_SUITE_COMMUNICATIONS = $00000008;
  VER_SUITE_TERMINAL = $00000010;
  VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020;
  VER_SUITE_EMBEDDEDNT = $00000040;
  VER_SUITE_DATACENTER = $00000080;
  VER_SUITE_SINGLEUSERTS = $00000100;
  VER_SUITE_PERSONAL = $00000200;
  VER_SUITE_BLADE = $00000400;
  VER_SUITE_EMBEDDED_RESTRICTED = $00000800;
  VER_SUITE_SECURITY_APPLIANCE = $00001000;




function GetVersionExA(var lpVersionInformation: TOSVersionInfo): BOOL; stdcall;
{$EXTERNALSYM GetVersionExA}
function GetVersionExW(var lpVersionInformation: TOSVersionInfo): BOOL; stdcall;
{$EXTERNALSYM GetVersionExW}
function GetVersionEx(var lpVersionInformation: TOSVersionInfo): BOOL; stdcall;
{$EXTERNALSYM GetVersionEx}

implementation

function GetVersionExA; external kernel32 name 'GetVersionExA';
function GetVersionExW; external kernel32 name 'GetVersionExW';
function GetVersionEx; external kernel32 name 'GetVersionExA';

end.
Bitte mal die verschiedenen Systeme durchprobieren (wer mehrere hat). Für 98 und XP kann ich schon mal das OK geben.
  Mit Zitat antworten Zitat
CalganX

Registriert seit: 21. Jul 2002
Ort: Bonn
5.403 Beiträge
 
Turbo Delphi für Win32
 
#3

Re: Windows-Version ermitteln

  Alt 26. Feb 2005, 17:20
MagicAndre1981 hat hier ein Update, das mehr Windows Versionen erkennt (auch Betas), als die ältere Version des Codes, gepostet:

Zitat seines Beitrages:

Quellen:
Code der unit zum Erkennen von Windows ist im Anhang.

Unterstütze Versionen:
  • Windows Vista
  • Windows Server 2003 (Standard, Web Edition, Enterprise, DataCenter, Standard Edition for Itanium-based Systems, Enterprise Edition for Itanium-based Systems, DataCenter Edition for Itanium-based Systems, Standard x64 Edition, Enterprise x64 Edition, DataCenter x64 Edition)
  • Windows Server 2003 R2
  • Windows XP Prof. x64 Edition
  • Windows XP Prof.
  • Windows XP Home
  • Windows XP Tablet Edition
  • Windows XP Media Center Edition
  • Windows 2000 (Prof., Server, DataCenter, Advanced Server + Betas (Codename NT5.0))
  • Windows NT 4 Server (Server, Enterprise Server, Advanced Server)
  • Windows NT 4 Workstation (mit Unterscheidunf zw. SP6 und SP6a)
  • Windows NT 3.51
  • Windows 95 (A,B,C + Betas (Codename: Chicago, Nashville))
  • Windows 98 (Original, SE + Betas (Codename: Memphis))
  • Windows ME (Original + BETA 1 (Codename: Georgia))

Offene Fragen:
  • Unterscheidung der MCE-Versionen (2002,2004,2005)
  • Erkennung der Windows XP N-Editions

Benutzung:

Delphi-Quellcode:
uses GetWindowsVersion;

Edit1.Text := GetWinVersion;
So, dann happy Windowserkenning

André


Edit=Matze]Beitrag und Anhänge aktualisiert. MfG, Matze
Angehängte Dateien
Dateityp: pas windows_fragment_645.pas (4,8 KB, 261x aufgerufen)
Dateityp: pas getwindowsversion_778.pas (11,6 KB, 345x aufgerufen)
  Mit Zitat antworten Zitat
Antwort Antwort

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz