请问怎样知道当前的操作系统是什么?(30分)

  • 主题发起人 主题发起人 sunny888
  • 开始时间 开始时间
function Winversion :string;<br>var osvi:OSVERSIONINFO;<br>begin<br>&nbsp; osvi.dwOSVersionInfoSize :=sizeof(osversioninfo);;<br>&nbsp; getversionex(osvi);<br>&nbsp; case osvi.dwPlatformId of<br>&nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32s:result:='Windows 3.1';<br>&nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_NT :result:='Windows NT';<br>&nbsp; &nbsp; &nbsp; &nbsp;VER_PLATFORM_WIN32_WINDOWS :result:='Windows 9x';<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>end;
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>const strOsType: array[0..7] of string=('osUnknown','osWin95','osWin98','osWin98se','osWinme','osWinnt4','osWin2k','osWinxp');<br>type OSType=(osUnknown,osWin95,osWin98,osWin98se,osWinme,osWinnt4,osWin2k,osWinxp);<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>Function GetOSVersion : OSType;<br>Var<br>&nbsp; osVerInfo : TOSVersionInfo;<br>&nbsp; majorVer, minorVer : Integer;<br>Begin<br><br>&nbsp; //Result := osUnknown;<br>&nbsp; osVerInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );<br>&nbsp; If ( GetVersionEx( osVerInfo ) ) Then <br>&nbsp; Begin<br>&nbsp; &nbsp; majorVer := osVerInfo.dwMajorVersion;<br>&nbsp; &nbsp; minorVer := osVerInfo.dwMinorVersion;<br>&nbsp; &nbsp; Case ( osVerInfo.dwPlatformId ) Of<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_NT : { Windows NT/2000 }<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( majorVer &lt;= 4 ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWinnt4<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 5 ) And ( minorVer= 0 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWin2k<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 5) And ( minorVer = 1 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWinxp<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsUnknown;<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS : { Windows 9x/ME }<br>&nbsp; &nbsp; &nbsp; Begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 4 ) And ( minorVer = 0 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWin95<br>&nbsp; &nbsp; &nbsp; &nbsp; Else If ( ( majorVer = 4 ) And ( minorVer = 10 ) ) Then <br>&nbsp; &nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If ( osVerInfo.szCSDVersion[ 1 ] = 'A' ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := osWin98se<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := osWin98;<br>&nbsp; &nbsp; &nbsp; &nbsp; End <br>&nbsp; &nbsp; &nbsp; &nbsp; Else If ( ( majorVer = 4) And ( minorVer = 90 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsWinME<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsUnknown;<br><br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; Result := OsUnknown;<br>&nbsp; &nbsp; End; //end of case<br>&nbsp; End Else<br>&nbsp; Result := OsUnknown;<br><br>End;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; ShowMessage(strOsType[integer(GetOSVersion)]);<br>end;<br><br>end.<br>
 
只能判断出以上三种结果吗?能不能具体到windows95/windows98/windows2000/winxp等?<br>
 
可以呀,仔细看一下上面。
 
to zw84611:<br>&nbsp; &nbsp;谢谢。<br>&nbsp; &nbsp;我想把GetOSVersion放到一个公用的Form里,在另外的Form调用这个函数。可是编译通不<br>过,提示strOSType没有定义,请问这该怎么解决?
 
to sunny888:<br><br>unit WinVer;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>const<br>&nbsp; strOsType: array[0..7] of string=('osUnknown','osWin95','osWin98','osWin98se','osWinme','osWinnt4','osWin2k','osWinxp');<br><br>type<br>&nbsp; OSType=(osUnknown,osWin95,osWin98,osWin98se,osWinme,osWinnt4,osWin2k,osWinxp);<br><br>Function GetOSVersion : OSType;<br><br>implementation<br><br>Function GetOSVersion : OSType;<br>Var<br>&nbsp; osVerInfo : TOSVersionInfo;<br>&nbsp; majorVer, minorVer : Integer;<br>Begin<br><br>&nbsp; //Result := osUnknown;<br>&nbsp; osVerInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );<br>&nbsp; If ( GetVersionEx( osVerInfo ) ) Then<br>&nbsp; Begin<br>&nbsp; &nbsp; majorVer := osVerInfo.dwMajorVersion;<br>&nbsp; &nbsp; minorVer := osVerInfo.dwMinorVersion;<br>&nbsp; &nbsp; Case ( osVerInfo.dwPlatformId ) Of<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_NT : { Windows NT/2000 }<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( majorVer &lt;= 4 ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWinnt4<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 5 ) And ( minorVer= 0 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWin2k<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 5) And ( minorVer = 1 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWinxp<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsUnknown;<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS : { Windows 9x/ME }<br>&nbsp; &nbsp; &nbsp; Begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; If ( ( majorVer = 4 ) And ( minorVer = 0 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := osWin95<br>&nbsp; &nbsp; &nbsp; &nbsp; Else If ( ( majorVer = 4 ) And ( minorVer = 10 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If ( osVerInfo.szCSDVersion[ 1 ] = 'A' ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := osWin98se<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := osWin98;<br>&nbsp; &nbsp; &nbsp; &nbsp; End<br>&nbsp; &nbsp; &nbsp; &nbsp; Else If ( ( majorVer = 4) And ( minorVer = 90 ) ) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsWinME<br>&nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := OsUnknown;<br><br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; Result := OsUnknown;<br>&nbsp; &nbsp; End; //end of case<br>&nbsp; End Else<br>&nbsp; Result := OsUnknown;<br>End;<br><br>end.<br>&nbsp;<br>
 
接受答案了.
 
后退
顶部