function GetWMIProperty(WMIType, WMIProperty: string): string;
var Wmi, Objs, Obj: OleVariant;
C: Cardinal;
i,Len:integer;
tempItem:IEnumVariant;
begin
Wmi:= CreateOleObject('WbemScripting.SWbemLocator');
Objs := Wmi.ConnectServer('.','root\cimv2').ExecQuery('Select * from Win32_' + WMIType);
tempItem:=IEnumVariant(IUnknown(Objs._NewEnum));
Result:='';
while (tempItem.Next(1, obj, c) = S_OK) do
begin
Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
if not VarIsNull(obj) then
begin
Result :=Result +trim(Obj);
break;
end;
end;
end;
呼叫函式查詢BIOS序列號
ShowMessage(GetWMIProperty('BIOS', 'SerialNumber'));結果顯示“RPC服務器不可用。",斷點停留在
Objs := Wmi.ConnectServer('.','root\cimv2').ExecQuery('Select * from Win32_' + WMIType);這一行。同樣用微軟的WMICodeCreator查詢,就可以正常查詢,是不是我哪里有錯誤?
uj5u.com熱心網友回復:
CoInitialize(nil);先呼叫他轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/46045.html
標籤:VCL組件開發及應用
