本文整理自网络,侵删。
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type {Rec_Wmi = record ComputerName: string; Namespace: string; User: string; Password: string; WMIType: string; Enum: IEnumVariant; class function GetWmiEnum(WMIType: string; var AEnum: IEnumVariant; Namespace: string = 'root\cimv2'; Where: string = ''; ComputerName: string = ''; User: string = ''; Password: string = ''): string; static; class function GetWMIProperty(Enum: IEnumVariant; WMIProperty: string; Index: integer = 0): OleVariant; static; class function SetWMIProperty(Enum: IEnumVariant; WMIProperty: string; value: string; Index: integer = 0): string; static; function GetEnum(Where: string = ''): string; function GetProperty(WMIProperty: string; Index: integer = 0): OleVariant; function SetProperty(WMIProperty: string; value: string): string; end;}
TForm1 = class(TForm) Btnv_1: TButton; procedure Btnv_1Click(Sender: TObject); private public end;
var Form1: TForm1;
implementationuses ActiveX,ComObj;
{$R *.dfm}
function GetWMIProperty(WMIType, WMIProperty:AnsiString):String;var Wmi, Objs, Obj:OleVariant; Enum:IEnumVariant; C:Cardinal;begin Result := ''; try Wmi:= CreateOleObject(AnsiString('WbemScripting.SWbemLocator')); Objs := Wmi.ConnectServer(AnsiString('.'),AnsiString('root\cimv2')).ExecQuery(AnsiString('SELECT * FROM WIN32_'+WMIType)); Enum:=IEnumVariant(IUnknown(Objs._NewEnum)); Enum.Reset; Enum.Next(1,Obj,C); Obj:=Obj.Properties_.Item(WMIProperty,0).Value; if VarIsArray(Obj) then begin Result:=Obj[0] end else begin Result := Obj; end; except Result:='error'; end;end;
procedure TForm1.Btnv_1Click(Sender: TObject);begin ShowMessage(GetWMIProperty('BIOS','BIOSVersion')); //获得BIOS版本 ShowMessage(GetWMIProperty('DiskDrive','SerialNumber')); //获得第一块硬盘的设备标示 ShowMessage(GetWMIProperty('Processor','ProcessorId')); //获得CPUID。end;
end.
相关阅读 >>
Delphi twebbrowser与嵌入youtube视频崩溃
Delphi中tapplicationevents控件的用途与使用方法
Delphi运行时的问题,cannot focus a disabled or invisible window!
更多相关阅读请进入《Delphi》频道 >>