function GetWinVersion: TWin32Version;
begin
Result := wvUnknown;
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
if (Win32MajorVersion > 4) or
((Win32MajorVersion = 4) and (Win32MinorVersion > 0)) then
Result := wvWin98
else
Result := wvWin95
else
if Win32MajorVersion <= 4 then
Result := wvWinNT
else
if Win32MajorVersion = 5 then
Result := wvWin2000
end;
if GetVersionEx(MyVersionInfo) then
Label1.Caption := IntToStr(MyVersionInfo.dwPlatformId)
else Label1.Caption := 'false';
if MyVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
Label1.Caption := 'Windows 95';
if MyVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
IsNT := True;
Label1.Caption := 'Windows NT';
end;
try
if IsNT then
if not MyReg.OpenKey('/SOFTWARE/Microsoft/Windows NT/CurrentVersion', FALSE) then
else Label2.Caption := MyReg.ReadString('CurrentVersion')
else
if not MyReg.OpenKey('/SOFTWARE/Microsoft/Windows/CurrentVersion', FALSE) then
else Label2.Caption := MyReg.ReadString('VersionNumber');
finally
end; // try..finally
end;
Declare Function GetVersion Lib "kernel32" Alias "GetVersion" () As Long
说明
判断当前运行的Windows和DOS版本
返回值
Long,低16位包含了windows版本;低字节包含了主版本号(3代表windows 3.10,4代表nt 4.0);高字节包含了两个数位的辅助版本号(10代表windows 3.10,95代表windows 95)。高16位则包含了平台信息。针对windows NT,高位设为0;针对windows for workgroups上运行的Win32s,则高位为1
注解
在win32下,最好换用GetVersionEx函数。在win32下,高字不会返回DOS版本