|
Thema geschlossen
|
Registriert seit: 21. Jul 2002 Ort: Bonn 5.403 Beiträge Turbo Delphi für Win32 |
#1
MagicAndre1981 hat hier ein Update für die in der Code-Library befindliche Funktion für das Herausfinden der verwendeten Windowsversion gepostet. Das Update beläuft sich hier (nur) auf den Teil, dass nun die Windows XP Media Center Edition erkannt wird:
Delphi-Quellcode:
Wie corgan anmerkte, muss unter Umständen noch folgende Unit - Windows_Fragment.dcu - noch zusätzlich in die Uses aufgenommen werden:
const
SM_MEDIACENTER = 87; // // 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 Begin // Unterscheidung zw. MCE und Prof. if GetSystemMetrics(SM_MEDIACENTER) <> 0 then Result := Result + 'Media Center Edition ' else Result := Result + 'Professional '; End; 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;
Delphi-Quellcode:
Chris
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. |
26. Feb 2005, 17:22
Dieses Thema wurde von "Chakotay1308" von "Neuen Beitrag zur Code-Library hinzufügen" nach "Windows API" verschoben.Beitrag befindet sich nun hier in der Code-Library. |
Ansicht |
Linear-Darstellung |
Zur Hybrid-Darstellung wechseln |
Zur Baum-Darstellung wechseln |
ForumregelnEs 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
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
LinkBack URL |
About LinkBacks |