delphi WMI 取硬件信息


本文整理自网络,侵删。

 
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;

implementation
uses
  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 多种方法查找窗口句柄

Delphi twebbrowser与嵌入youtube视频崩溃

Delphi中用socket解析域名获得ip地址

Delphi中tapplicationevents控件的用途与使用方法

Delphi运行时的问题,cannot focus a disabled or invisible window!

Delphi读取文本(一行一行读入)

Delphi tdownloadurl下载网络文件

Delphi里实现彩色图片转为黑白图像的功能

Delphi idhttp登录网站教程代码

Delphi 数组复制利用copymemory 最为完美

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...