const strOsType: array[0..7] of string=('osUnknown','osWin95','osWin98','osWin98se','osWinme','osWinnt4','osWin2k','osWinxp');
type OSType=(osUnknown,osWin95,osWin98,osWin98se,osWinme,osWinnt4,osWin2k,osWinxp);
Function GetOSVersion : OSType;
Var
osVerInfo : TOSVersionInfo;
majorVer, minorVer : Integer;
Begin
//Result := osUnknown;
osVerInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );
If ( GetVersionEx( osVerInfo ) ) Then
Begin
majorVer := osVerInfo.dwMajorVersion;
minorVer := osVerInfo.dwMinorVersion;
Case ( osVerInfo.dwPlatformId ) Of
VER_PLATFORM_WIN32_NT : { Windows NT/2000 }
Begin
If ( majorVer <= 4 ) Then
Result := osWinnt4
Else
If ( ( majorVer = 5 ) And ( minorVer= 0 ) ) Then
Result := osWin2k
Else
If ( ( majorVer = 5) And ( minorVer = 1 ) ) Then
Result := osWinxp
Else
Result := OsUnknown;
End;
VER_PLATFORM_WIN32_WINDOWS : { Windows 9x/ME }
Begin
If ( ( majorVer = 4 ) And ( minorVer = 0 ) ) Then
Result := osWin95
Else If ( ( majorVer = 4 ) And ( minorVer = 10 ) ) Then
Begin
If ( osVerInfo.szCSDVersion[ 1 ] = 'A' ) Then
Result := osWin98se
Else
Result := osWin98;
End
Else If ( ( majorVer = 4) And ( minorVer = 90 ) ) Then
Result := OsWinME
Else
Result := OsUnknown;
End;
Else
Result := OsUnknown;
End; //end of case
End Else
Result := OsUnknown;
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(strOsType[integer(GetOSVersion)]);
end;