function GetWMIProperty (WMIType WMIProperty: string) : string;
Var Wmi, Objs, Obj: OleVariant;
C: the Cardinal;
I, Len: integer;
TempItem: IEnumVariant;
The 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
The begin
Obj:=Obj. Properties_. Item (WMIProperty, 0). The Value;
If not VarIsNull (obj) then
The begin
Result: the Result=+ trim (Obj);
break;
end;
end;
end;
Call a function query BIOS serial number
ShowMessage (GetWMIProperty (' BIOS ', 'SerialNumber));
Results show that the RPC server is unavailable, "", breakpoints in
Objs:=Wmi. ConnectServer ('. ', 'root \ cimv2). ExecQuery (' Select * from Win32_' + WMIType); The,
Same with Microsoft WMICodeCreator query, can normal query, isn't me where there is a mistake?
CodePudding user response:
CoInitialize (nil); Call him first