怎样得到当前的操作系统的版本号如win98,win95,winxp,win2000等 (15分)

  • 主题发起人 bravercaohao
  • 开始时间
B

bravercaohao

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样用Delphi得到当前的操作系统的版本号如win98,win95,winxp,win2000等
 
很多,贴上来了一些。[:D]<br>{--------------------------------------------------------------------------}<br>{1、获取当前Windows的版本}<br>const<br>&nbsp; cOsUnknown = -1;<br>&nbsp; cOsWin95 = 0;<br>&nbsp; cOsWin98 = 1;<br>&nbsp; cOsWin98SE = 2;<br>&nbsp; cOsWinME = 3;<br>&nbsp; cOsWinNT = 4;<br>&nbsp; cOsWin2000 = 5;<br>&nbsp; cOsXP = 6;<br><br><br>function GetOperatingSystem: Integer;<br>var<br>&nbsp; osVerInfo: TOSVersionInfo;<br>&nbsp; majorVer, minorVer: Integer;<br>begin<br>&nbsp; Result := cOsUnknown;<br>&nbsp; { set operating system type flag }<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; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if majorVer &lt;= 4 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWinNT<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (majorVer = 5) and (minorVer = 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWin2000<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (majorVer = 5) and (minorVer = 1) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsXP<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsUnknown; <br>&nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS: &nbsp;{ Windows 9x/ME } <br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (majorVer = 4) and (minorVer = 0) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWin95 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (majorVer = 4) and (minorVer = 10) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if osVerInfo.szCSDVersion[1] = 'A' then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWin98SE <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWin98; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (majorVer = 4) and (minorVer = 90) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsWinME <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := cOsUnknown; <br>&nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; Result := cOsUnknown; <br>&nbsp; &nbsp; end; <br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; Result := cOsUnknown; <br>end; <br><br>{--------------------------------------------------------------------------}<br>{2、判断当前OS是否属于那一个}<br>function IsXP: Boolean;<br>var<br>&nbsp; OS: TOSVERSIONINFO;<br>begin<br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);<br>&nbsp; GetVersionEx(osv);<br>&nbsp; Result := (OS.dwPlatformId = VER_PLATFORM_WIN32_NT) and<br>&nbsp; &nbsp; (OS.dwMajorVersion = 5) and (OS.dwMinorVersion = 1);<br>end;<br><br>function IsWin2000: Boolean; <br>var<br>&nbsp; OS: TOSVersionInfo; <br>begin <br>&nbsp; ZeroMemory(@OS, SizeOf(OS)); <br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS); <br>&nbsp; GetVersionEx(OS); <br>&nbsp; Result := (OS.dwMajorVersion &gt;= 5) and <br>&nbsp; &nbsp; (OS.dwPlatformId = VER_PLATFORM_WIN32_NT); <br>end; <br><br><br>function IsWinNT2: Boolean;<br>var <br>&nbsp; OS: TOSVersionInfo; <br>begin <br>&nbsp; ZeroMemory(@OS, SizeOf(OS)); <br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS); <br>&nbsp; GetVersionEx(OS); <br>&nbsp; Result := OS.dwPlatformId = VER_PLATFORM_WIN32_NT; <br>end; <br><br>{ or: }<br><br>function IsWinNT2: Boolean;<br>begin<br>&nbsp; Result := Win32Platform = VER_PLATFORM_WIN32_NT;<br>end;<br><br><br>function IsWinME: Boolean;<br>var<br>&nbsp; OS: TOSVersionInfo;<br>begin<br>&nbsp; ZeroMemory(@OS, SizeOf(OS));<br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS);<br>&nbsp; GetVersionEx(OS);<br>&nbsp; Result := (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) and<br>&nbsp; &nbsp; (OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);<br>end;<br><br><br>function IsWin95: Boolean;<br>var<br>&nbsp; OS: TOSVersionInfo;<br>begin<br>&nbsp; ZeroMemory(@OS, SizeOf(OS));<br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS);<br>&nbsp; GetVersionEx(OS);<br>&nbsp; Result := (OS.dwMajorVersion &gt;= 4) and (OS.dwMinorVersion = 0) and<br>&nbsp; &nbsp; (OS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);<br>end;<br><br><br>uses registry;<br><br>function GetWindowsVersion: string;<br>var<br>&nbsp; VerInfo: TOsversionInfo;<br>&nbsp; PlatformId, VersionNumber: string;<br>&nbsp; Reg: TRegistry;<br>begin<br>&nbsp; VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);<br>&nbsp; GetVersionEx(VerInfo);<br>&nbsp; // Detect platform<br>&nbsp; Reg := TRegistry.Create; <br>&nbsp; Reg.RootKey := HKEY_LOCAL_MACHINE; <br>&nbsp; case VerInfo.dwPlatformId of <br>&nbsp; &nbsp; VER_PLATFORM_WIN32s: <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; // Registry (Huh? What registry?) <br>&nbsp; &nbsp; &nbsp; &nbsp; PlatformId := 'Windows 3.1'; <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS: <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; // Registry <br>&nbsp; &nbsp; &nbsp; &nbsp; Reg.OpenKey('/SOFTWARE/Microsoft/Windows/CurrentVersion', False); <br>&nbsp; &nbsp; &nbsp; &nbsp; PlatformId &nbsp; &nbsp;:= Reg.ReadString('ProductName'); <br>&nbsp; &nbsp; &nbsp; &nbsp; VersionNumber := Reg.ReadString('VersionNumber'); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; VER_PLATFORM_WIN32_NT: <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; // Registry<br>&nbsp; &nbsp; &nbsp; &nbsp; Reg.OpenKey('/SOFTWARE/Microsoft/Windows NT/CurrentVersion', False); <br>&nbsp; &nbsp; &nbsp; &nbsp; PlatformId &nbsp; &nbsp;:= Reg.ReadString('ProductName'); <br>&nbsp; &nbsp; &nbsp; &nbsp; VersionNumber := Reg.ReadString('CurrentVersion'); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; end; <br>&nbsp; Reg.Free; <br>&nbsp; Result := PlatformId + ' (version ' + VersionNumber + ')'; <br>end; <br><br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>&nbsp; Caption := GetWindowsVersion;<br>end;<br>
 
或者用简单的方法。<br><br>你到注册表里面看看,也许会有收获。<br><br>HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion
 
yzhshi 你好:<br>&nbsp; &nbsp; &nbsp;你的代码在win98,winxp上通过但好像不能区分win2000和win2000 Server
 
2000 Server、Adv Server 、Personal<br>这个我倒还没有试验过,你看一下小版本是否有区别<br>就是下面的minorVer的数值<br>&nbsp; &nbsp;majorVer := osVerInfo.dwMajorVersion; &nbsp; 5<br>&nbsp; &nbsp;minorVer := osVerInfo.dwMinorVersion; &nbsp; ?<br>我这里没有环境,呵呵。
 
[:)]太夸張了吧﹐yzhshi<br>buttonclick<br>var<br>&nbsp; osvi:eek:sversioninfo;<br>begin<br>&nbsp; ovsi.dwosversioninfosize:=sizeof (osversioninfo);<br>&nbsp; getversionex(osvi); <br>&nbsp; label1.caption:=inttostr(osvi.dwmajorversion)+','<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+inttostr(osvi.dwminorversion)+','<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+inttostr(osvi.dwbuildnumber)+','<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+inttostr(osve.dwplatformid)+','<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+osvi.szcsdversion;<br>end;<br><br><br><br><br>&nbsp; &nbsp;
 
Win32PlatForm<br>系统预定义的
 
顶部