刚刚写了一个函数,拿去用就行了:[
]
function GetWinVersionInfo: string;
type
OSVERSIONINFOEXA = record
dwOSVersionInfoSize: DWORD;
dwMajorVersion: DWORD;
dwMinorVersion: DWORD;
dwBuildNumber: DWORD;
dwPlatformId: DWORD;
szCSDVersion: array[0..127] of Char;
wServicePackMajor: Word;
wServicePackMinor: Word;
wSuiteMask: Word;
wProductType: Byte;
wReserved: Byte;
end;
TGetVersionExA = function(lpVersionInformation: POSVersionInfo): BOOL; stdcall;
const
VER_NT_WORKSTATION = $0000001;
VER_NT_SERVER = $0000003;
VER_SUITE_ENTERPRISE = $00000002;
VER_SUITE_DATACENTER = $00000080;
VER_SUITE_PERSONAL = $00000200;
var
GetVersionExA: TGetVersionExA;
OsVersionEx: OSVERSIONINFOEXA;
LibHandle: THandle;
AOsName: string;
bOsVersionInfoEx: Boolean;
FKey: hKey;
szProductType: string;
dwBufLen: DWORD;
begin
AOsName := 'Unknown Windows Version';
LibHandle := LoadLibrary(kernel32);
if LibHandle > 0 then
try
@GetVersionExA := GetProcAddress(LibHandle, 'GetVersionExA');
if @GetVersionExA <> nil then
begin
FillChar(OsVersionEx, SizeOf(OSVERSIONINFOEXA), 0);
OsVersionEx.dwOSVersionInfoSize := SizeOf(OSVERSIONINFOEXA);
bOsVersionInfoEx := GetVersionExA(POSVersionInfo(@OsVersionEx));
if not bOsVersionInfoEx then
begin
FillChar(OsVersionEx, SizeOf(TOSVersionInfo), 0);
OsVersionEx.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
if not GetVersionExA(POSVersionInfo(@OsVersionEx)) then
RaiseLastOSError;
end;
with OsVersionEx do
begin
case dwPlatformId of
VER_PLATFORM_WIN32_NT:
begin
if dwMajorVersion <= 4 then
AOsName := 'Microsoft Windows NT'
else if (dwMajorVersion = 5) and (dwMinorVersion = 0) then
AOsName := 'Microsoft Windows 2000'
else if (dwMajorVersion = 5) and (dwMinorVersion = 1) then
AOsName := 'Microsoft Windows XP';
if bOsVersionInfoEx then
begin
if wProductType = VER_NT_WORKSTATION then
begin
if wSuiteMask and VER_SUITE_PERSONAL = VER_SUITE_PERSONAL then
AOsName := AOsName + ' Personal'
else
AOsName := AOsName + ' Professional';
end
else if wProductType = VER_NT_SERVER then
begin
if (wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
AOsName := AOsName + ' DataCenter Server'
else if (wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
AOsName := AOsName + ' Advanced Server'
else
AOsName := AOsName + ' Server';
end;
end
else
begin
RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/ProductOptions',
0, KEY_QUERY_VALUE, FKey);
dwBufLen := 20;
SetLength(szProductType, dwBufLen);
RegQueryValueEx(FKey, 'ProductType', nil, nil, PByte(szProductType), @dwBufLen);
RegCloseKey(FKey);
SetLength(szProductType, dwBufLen);
if UpperCase(Trim(szProductType)) = 'WINNT' then
AOsName := AOsName + ' Workstation'
else if UpperCase(Trim(szProductType)) = 'SERVERNT' then
AOsName := AOsName + ' Server';
end;
if (dwMajorVersion <= 4) then
begin
AOsName := Format('%s Version %d.%d %s(Build %d)',
[AOsName, dwMajorVersion, dwMinorVersion, szCSDVersion,
dwBuildNumber and $FFFF]);
end
else
begin
AOsName := Format('%s %s(Build %d)', [AOsName, szCSDVersion,
dwBuildNumber and $FFFF]);
end;
end;
VER_PLATFORM_WIN32_WINDOWS:
begin
if (dwMajorVersion = 4) and (dwMinorVersion = 0) then
begin
AOsName := 'Microsoft Windows 95';
if (szCSDVersion[1] = 'C') then
AOsName := AOsName + ' OSR2';
end
else if (dwMajorVersion = 4) and (dwMinorVersion = 10) then
begin
AOsName := 'Microsoft Windows 98';
if szCSDVersion[1] = 'A' then
AOsName := AOsName + ' SE';
end
else if (dwMajorVersion = 4) and (dwMinorVersion = 90) then
begin
AOsName := 'Microsoft Windows Me';
end;
end;
VER_PLATFORM_WIN32s:
begin
AOsName := 'Microsoft Win32s';
end;
end;
end;
end;
finally
FreeLibrary(LibHandle);
end;
Result := AOsName;
end;