Delphi中判断Windows操作系统版本

2016-08-22 10:23:57来源:http://kivinliu.blog.51cto.com/10078601/1662941作者:Kivin_Liu人点击


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 = class(TForm)

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 := SizeOf(TOSVersioninfoA);

if GetVersionExA(VI) then

with VI do

Result := Trim (

Format(

'%d.%d build %d %s',

[dwMajorVersion, dwMinorVersion,dwBuildNumber,szCSDVersion]

)

)

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',[Win32MajorVersion, Win32MinorVersion]));

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.


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台