Es gibt zwar schon etliche Beiträge zu diesem Thema, aber die geben immer nur ein String zurück z.B.:
http://www.delphipraxis.net/6717-win...ermitteln.html
Um einfach mal zu Prüfen welche Version installiert ist müsste man den String vergleichen, unschön.
Daher hab ich mal die oben beschriebene Version angepasst. Die Ausgabe ist zwar nicht ganz MS konform (RWinVersion), aber so ist eine schnelle und verständliche Abfrage möglich.
Hier z.B. die Abfrage nach Windows 7
Delphi-Quellcode:
if (GetWinVersion.PlatformID = 2) and (GetWinVersion.Major = 6) and (GetWinVersion.Minor = 2) then
...
Hier der Code:
Code:
interface
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;
VER_NT_WORKSTATION = $0000001;
VER_NT_DOMAIN_CONTROLLER = $0000002;
VER_NT_SERVER = $0000003;
SM_SERVERR2 = 89; // Windows Server 2003 R2
PROCESSOR_ARCHITECTURE_INTEL = 0;
PROCESSOR_ARCHITECTURE_MIPS = 1;
PROCESSOR_ARCHITECTURE_ALPHA = 2;
PROCESSOR_ARCHITECTURE_PPC = 3;
PROCESSOR_ARCHITECTURE_SHX = 4;
PROCESSOR_ARCHITECTURE_ARM = 5;
PROCESSOR_ARCHITECTURE_IA64 = 6;
PROCESSOR_ARCHITECTURE_ALPHA64 = 7;
PROCESSOR_ARCHITECTURE_MSIL = 8;
PROCESSOR_ARCHITECTURE_AMD64 = 9;
PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10;
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;
RWinVersion = record
PlatformID : integer;
// VER_PLATFORM_WIN32s = 0;
// VER_PLATFORM_WIN32_WINDOWS = 1;
// VER_PLATFORM_WIN32_NT = 2;
// VER_PLATFORM_WIN32_CE = 3;
Major : integer;
Minor : integer;
Typ : integer;
// PlatformID = 1
// Major = 4
// Minor = 0 95
// Minor = 1 95 B
// Minor = 2 95 C
// Minor = 3 98
// Minor = 4 98 SE
// Minor = 5 ME
// PlatformID = 2
// Major = 3
// Minor = 0 NT 3.5
// Major = 4
// Minor = 0 NT 4 // Typ 0 = Workstation, 1 = Server Standard, 2 = Server Enterprise
// Major = 5
// Minor = 0 2000 // Typ 0 = , 1 = Data Center, 2 = Advanced
// Minor = 1 XP // Typ 0 = Home, 1 = Professional, 2 = Professional x64
// Minor = 2 Server 2003 // Typ 0 = Enterprise, 1 = Data Center, 2 = Web Edition, 3 = Standard
// Minor = 3 Home Server
// Minor = 4 Server 2003 R2
// Major = 6
// Minor = 0 Vista // Typ 0 = Ultimate Business, 1 = Home Basic/Premium
// Minor = 1 Server 2008 // Typ 0 = Standard, 1 = Enterprise, 2 = Data Center, 3 = R2
// Minor = 2 7
end;
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}
function GetWinVersion: RWinVersion;
implementation
function GetWinVersion: RWinVersion;
function GetNativeSystemInfoEx : SYSTEM_INFO;
var
po :TFarProc;
DLLWnd :THandle;
SI :SYSTEM_INFO;
GetNativeSystemInfo:procedure(var LPSYSTEM_INFO:SYSTEM_INFO);stdcall;
begin
po := nil;
DLLWnd := LoadLibrary('kernel32');
if DLLWnd > 0 then
begin
try
po := GetProcAddress(DLLWnd, 'GetNativeSystemInfo');
if po <> nil then
begin
@GetNativeSystemInfo := po;
GetNativeSystemInfo(SI);
result := SI;
end;
finally
FreeLibrary(DLLWnd);
end;
end;
end;
var
osvi : TOSVersionInfo;
bOsVersionInfoEx : boolean;
si : SYSTEM_INFO;
begin
Result.PlatformID := -1;
Result.Major := -1;
Result.Minor := -1;
Result.Typ := -1;
// 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
Exit;
end;
end;
si := GetNativeSystemInfoEx;
Result.PlatformID := osvi.dwPlatformId;
case osvi.dwPlatformId of
{$REGION 'VER_PLATFORM_WIN32_WINDOWS'}
VER_PLATFORM_WIN32_WINDOWS:
begin
if (osvi.dwMajorVersion = 4) then
begin
{$REGION 'Windows 95'}
if (osvi.dwMinorVersion = 0) then
begin
Result.Major := 4;
case LOWORD(osvi.dwBuildNumber) of
122, 189, 347, 480, 950 : Result.Minor := 0;
999, 1111, 1212, 1213 : Result.Minor := 1;
1214 : Result.Minor := 2;
end;
end;
{$ENDREGION}
{$REGION 'Windows 98'}
if (osvi.dwMinorVersion = 10) then
begin
if(osvi.szCSDVersion[0] = 'A') then
Result.Minor := 3
else
Result.Minor := 4;
end;
{$ENDREGION}
{$REGION 'Windows ME'}
if (osvi.dwMinorVersion = 90) then
begin
Result.Minor := 5;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
{$REGION 'VER_PLATFORM_WIN32_NT'}
VER_PLATFORM_WIN32_NT :
begin
case osvi.dwMajorVersion of
{$REGION 'NT 3.5'}
3 : begin
Result.Major := 3;
Result.Minor := 0;
end;
{$ENDREGION}
{$REGION 'NT 4'}
4 : begin
Result.Major := 4;
Result.Minor := 0;
case osvi.wProductType of
1 : Result.Typ := 0; // Workstation
3 : begin
case osvi.wSuiteMask of
0 : Result.Typ := 1; // Server Standard
2 : Result.Typ := 2; // Server Enterprise
end;
end;
end;
end;
{$ENDREGION}
{$REGION '2000-Server 2003 R2'}
5 : begin
Result.Major := 5;
case osvi.dwMinorVersion of
{$REGION '2000'}
0 : begin
Result.Minor := 0;
Result.Typ := 0;
if osvi.wSuiteMask = 80 then
Result.Typ := 1;
if osvi.wProductType = 2 then
Result.Typ := 2;
end;
{$ENDREGION}
{$REGION 'XP'}
1 : begin
Result.Minor := 1;
Result.Typ := 0;
if (osvi.wSuiteMask and 200 = 0) then
Result.Typ := 1;
end;
{$ENDREGION}
{$REGION 'XP x64, Server 2003, Home Server, Server 2003 R2'}
2 : begin
{$REGION 'XP x64'}
if (osvi.wProductType = VER_NT_WORKSTATION) and
(si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64)
then
begin
Result.Minor := 1;
Result.Typ := 2;
end
{$ENDREGION}
else
begin
{$REGION 'Server 2003 R2'}
if GetSystemMetrics(SM_SERVERR2) <> 0 then
begin
Result.Minor := 4;
end
{$ENDREGION}
else
begin
case osvi.wSuiteMask of
{$REGION 'Server 2003'}
0 : begin // Standard
Result.Minor := 2;
Result.Typ := 3;
end;
2 : begin // Enterprise
Result.Minor := 2;
Result.Typ := 0;
end;
80 : begin // Data Center
Result.Minor := 2;
Result.Typ := 1;
end;
400 : begin // Web Edition
Result.Minor := 2;
Result.Typ := 2;
end;
{$ENDREGION}
{$REGION 'Home Server'}
8000 : begin
Result.Minor := 3;
end;
{$ENDREGION}
end;
end;
end;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
{$REGION 'Vista-7'}
6 : begin
Result.Major := 6;
case osvi.dwMinorVersion of
{$REGION 'Vista, Server 2008'}
0 : begin
case osvi.wProductType of
{$REGION 'Vista'}
1 : begin
Result.Minor := 0;
if osvi.wSuiteMask = 0 then // Ultimate Business
Result.Typ := 0;
if osvi.wSuiteMask = 200 then // Home Basic/Premium
Result.Typ := 1;
end;
{$ENDREGION}
{$REGION 'Server 2008'}
3 : begin
Result.Minor := 1;
if osvi.wSuiteMask = 0 then // Standard
Result.Typ := 0;
if osvi.wSuiteMask = 2 then // Enterprise
Result.Typ := 1;
if osvi.wSuiteMask = 80 then // Data Center
Result.Typ := 1;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
{$REGION 'Server 2008 R2, 7'}
1 : begin
case osvi.wProductType of
{$REGION 'Server 2008 R2'}
3 : begin
Result.Minor := 1;
Result.Typ := 3;
end;
{$ENDREGION}
{$REGION '7'}
1 : begin
Result.Minor := 2;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
end;
end;
{$ENDREGION}
end;
end;
function GetVersionExA; external kernel32 name 'GetVersionExA';
function GetVersionExW; external kernel32 name 'GetVersionExW';
function GetVersionEx; external kernel32 name 'GetVersionExA';
leider muß ich den Code Tag nehmen, da der Delphi-Quellcode Tag die Leerzeichen in den Kommentaren zusammenschrumft