onst
OS_WINNT = 1; { WINDOWS NT}
OS_WIN32 = 0; { WINDOWS 95 OR 98}
OS_WINS = 2; { WIN32 OR WIN3.1}
OS_WINNT4 = 3; { WINNT 4 }
OS_WIN2k = 4; { Win2k }
function WinVer: Integer;
var
OSVerInfo: TOSVersionInfo;
begin
try
OSVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
GetVersionEx(OSVerInfo);
result := OSVerInfo.dwMajorVersion;
case OSVerInfo.dwPlatformID of
VER_PLATFORM_WIN32s: Result := OS_WINS;
VER_PLATFORM_WIN32_WINDOWS: result := OS_WIN32;
VER_PLATFORM_WIN32_NT: begin
case OSVerInfo.dwMajorVersion of
1: result := OS_WINNT;
2: result := OS_WINNT;
3: result := OS_WINNT;
4: result := OS_WINNT4;
5: result := OS_WIN2k;
end;
end
else
result := OSVerInfo.dwPlatformID;
end;
except
result := -1;
end;
end;
以上是我自己的函数,可是不能分辨Winme和WINXP和Win98se???
function GetWindowsVersion: string;
var
// windows api structure
VersionInfo: TOSVersionInfo;
begin
// get size of the structure
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
// populate the struct using api call
GetVersionEx(VersionInfo);
// platformid gets the core platform
// major and minor versions also included.
with VersionInfo do
begin
case dwPlatformid of
0 : begin
result := 'Windows 3.11';
end; // end 0
1 : begin
case dwMinorVersion of
0 : result := 'Windows 95';
10: begin
if ( szCSDVersion[ 1 ] = 'A' ) then
Result :='Windows 98 SE'
else
Result := 'Windows 98';
end; // end 10
90 : result := 'Windows Millenium';
else
result := 'Unknown Version';
end; // end case
end; // end 1
2 : begin
case dwMajorVersion of
3 : result := 'Windows NT ' +
IntToStr(dwMajorVersion) + '.' +
IntToStr(dwMinorVersion);
4 : result := 'Windows NT ' +
IntToStr(dwMajorVersion) + '.' +
IntToStr(dwMinorVersion);
5 : begin
case dwMinorVersion of
0 : result := 'Windows 2000';
1 : result := 'Windows Whistler';
end; // end case
end; // end 5
else
result := 'Unknown Version';
end; // end case
// service packs apply to the NT/2000 platform
if szCSDVersion <> '' then
result := result + ' Service pack: ' + szCSDVersion;
end; // end 2
else
result := 'Unknown Platform';
end; // end case
// add build info.
result := result + ', Build: ' +
IntToStr(Loword(dwBuildNumber)) ;
end; // end version info
end; // GetWindowsVersion