参考以下代码:方法一: function TForm1.GetWindowsVersion: string; var VersionInfo: TOSVersionInfo; begin VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo); GetVersionEx(VersionInfo); 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 ================================================ 方法二: procedure TForm1.Button5Click(Sender: TObject); var osinfo: OSVERSIONINFO; begin osinfo.dwOSVersionInfoSize := sizeof(OSVERSIONINFO); GetVersionEx(osinfo); ShowMessage(InttoStr(osinfo.dwMajorVersion) + '.' + IntToStr(osinfo.dwMinorVersion) + '.' + IntToStr(osinfo.dwBuildNumber)); end;备注: windows me 4.90.73010104 windows 2000 5.0.2195 windows 98 4.10.67766446 windows xp 5.1.2600
function TForm1.GetWindowsVersion: string;
var
VersionInfo: TOSVersionInfo;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
GetVersionEx(VersionInfo);
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
================================================
方法二:
procedure TForm1.Button5Click(Sender: TObject);
var
osinfo: OSVERSIONINFO;
begin
osinfo.dwOSVersionInfoSize := sizeof(OSVERSIONINFO);
GetVersionEx(osinfo);
ShowMessage(InttoStr(osinfo.dwMajorVersion) + '.' + IntToStr(osinfo.dwMinorVersion) + '.' + IntToStr(osinfo.dwBuildNumber));
end;备注:
windows me 4.90.73010104
windows 2000 5.0.2195
windows 98 4.10.67766446
windows xp 5.1.2600
Console.WriteLine(Environment.OSVersion);