通过API函数得到操作系统类型

时间:2010-01-29 08:56:22  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, CommDlg; typeTForm1 = class(TForm)Button1: TButton;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end; typeTOSVersion = (osUnknown, os95, os...
  正文:请看下面的代码:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, CommDlg;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TOSVersion = (osUnknown, os95, os95OSR2, os98, os98SE, osNT3, osNT4, os2K, osME, osXP);

var
Form1: TForm1;

implementation

{$R *.DFM}

function GetOS :TOSVersion;
var
OS :TOSVersionInfo;
begin
  ZeroMemory(@OS,SizeOf(OS));
  OS.dwOSVersionInfoSize:=SizeOf(OS);
  GetVersionEx(OS);
  Result:=osUnknown;
  if OS.dwPlatformId=VER_PLATFORM_WIN32_NT then begin
    case OS.dwMajorVersion of
    3: Result:=osNT3;
    4: Result:=osNT4;
    5: Result:=os2K;
  end;
  if (OS.dwMajorVersion=5) and (OS.dwMinorVersion=1) then
  Result:=osXP;
end else begin
  if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=0) then begin
    Result:=os95;
    if (Trim(OS.szCSDVersion)='B') then
    Result:=os95OSR2;
  end else
  if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=10) then begin
    Result:=os98;
    if (Trim(OS.szCSDVersion)='A') then
    Result:=os98SE;
  end else
  if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=90) then
  Result:=osME;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
os:TosVersion;
osVersion:string;
begin
  os:=Getos;
  case OS of
  os95, os95OSR2: OSVersion:='Windows 95';
  os98: OSVersion:='Windows 98';
  os98SE: OSVersion:='Windows 98 第二版';
  osME: OSVersion:='Windows Millenium Edition';
  osNT3, osNT4: OSVersion:='Windows NT';
  os2K: OSVersion:='Windows 2000';
  osXP: OSVersion:='Windows XP';
end;
showmessage(osversion);
end;

end.
通过API函数得到操作系统类型》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12586.html


关键字:

关于《通过API函数得到操作系统类型》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td