hao1nan 发表于 2018-6-21 08:50:09

Delphi中判断Windows操作系统版本

  unit GetSystemVersion;
  interface
  uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;
  type

  TMainFrm =>  edt1: TEdit;
  lbl1: TLabel;
  btn1: TBitBtn;
  procedure btn1Click(Sender: TObject);
  private
  { Private declarations }
  public
  { Public declarations }
  function GetWindowsVersionString: AnsiString;
  function GetWindowsVersion: String;
  end;
  var
  MainFrm: TMainFrm;
  implementation
  {$R *.dfm}
  function TMainFrm.GetWindowsVersionString : AnsiString;
  var
  VI: TOSVersionInfoA;
  begin

  VI.dwOSVersionInfoSize :=>  if GetVersionExA(VI) then
  with VI do
  Result := Trim (
  Format(
  '%d.%d build %d %s',
  
  )
  )
  else
  Result:= '';
  end;
  procedure TMainFrm.btn1Click(Sender: TObject);
  begin
  edt1.Text := GetWindowsVersion;
  end;
  function TMainFrm.GetWindowsVersion : String;
  var
  AWin32Version : Extended;
  OS: string;
  begin
  OS:= 'Windows';
  AWin32Version := StrToFloat(Format('%d.%d',));
  if Win32Platform = VER_PLATFORM_WIN32s then
  Result := OS + '32'
  else if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  begin
  if AWin32Version = 4.0 then
  Result := OS + '95'
  else if AWin32Version = 4.1 then
  Result := OS + '98'
  else if AWin32Version = 4.9 then
  Result := OS + 'Me'
  else
  Result := OS + '9X'
  end
  else if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
  if AWin32Version = 3.51 then
  Result := OS + 'NT 3.51'
  else if AWin32Version = 4.0 then
  Result := OS + 'NT 4.0'
  else if AWin32Version = 5.0 then
  Result :=OS + '2000'
  else if AWin32Version = 5.1 then
  Result := OS + 'XP'
  else if AWin32Version = 5.2 then
  Result := OS + '2003'
  else if AWin32Version = 6.0 then
  Result:=OS +'Vista'
  else if AWin32Version = 6.1 then
  Result := OS + '7'
  else if AWin32Version = 6.2 then
  Result := OS + '8'
  else
  Result := OS + 'Other NT Kernal Windows';
  end
  else
  Result := OS;
  end;
  end.
页: [1]
查看完整版本: Delphi中判断Windows操作系统版本