获取硬件标识

来源:互联网 发布:网络品牌注册怎么办理 编辑:程序博客网 时间:2024/05/18 11:25
通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
Delphi通过WMI获取系统信息
uses ActiveX, ComObj;

function GetWMIProperty(WMIType, WMIProperty: string): string;
var
  Wmi, Objs, Obj: OleVariant;
  Enum: IEnumVariant;
  C: Cardinal;
begin
  Wmi:= CreateOleObject('WbemScripting.SWbemLocator');
  Objs := Wmi.ConnectServer('.','root/cimv2').ExecQuery('Select * from Win32_' + WMIType);
  Enum := IEnumVariant(IUnknown(Objs._NewEnum));
  Enum.Reset;
  Enum.Next(1, Obj, C);
  Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
  Result := Obj;
end;
 

// 获取硬盘序列号
ShowMessage(GetWMIProperty('DiskDrive', 'PNPDeviceID'));
// 获取BISO序列号
ShowMessage(GetWMIProperty('BIOS', 'SerialNumber'));
// 获取网卡MAC地址
ShowMessage(GetWMIProperty('NetworkAdapter', 'MACAddress'));
// 获取网卡序列号
ShowMessage(GetWMIProperty('NetworkAdapter', 'PNPDeviceID'));
// 获取CPU序列号
ShowMessage(GetWMIProperty('Processor', 'ProcessorId'));

也可以用同样的方法获得任意感兴趣的系统信息,比如正在运行的进程、账户信息等等。

更多WMI的信息参考:
http://www.microsoft.com/whdc/system/pnppwr/wmi/default.mspx
http://msdn2.microsoft.com/en-us/library/aa394572.aspx
原创粉丝点击