1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| uses
SysUtils, Variants, ActiveX, WbemScripting_TLB;
function GetWMIString(wmiClass, wmiProperty : string):string;
var
Locator: ISWbemLocator;
Services: ISWbemServices;
SObject: ISWbemObject;
ObjSet: ISWbemObjectSet;
SProp: ISWbemProperty;
Enum: IEnumVariant;
Value: Cardinal;
TempObj: OleVariant;
begin
try
Locator := CoSWbemLocator.Create;
Services := Locator.ConnectServer('', 'root\cimv2', '', '', '','', 0, nil);
ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL', wbemFlagReturnImmediately and wbemFlagForwardOnly , nil);
Enum := ObjSet._NewEnum as IEnumVariant;
while Enum.Next(1, TempObj, Value) = S_OK do
begin
SObject := IUnknown(tempObj) as ISWBemObject;
SProp := SObject.Properties_.Item(wmiProperty, 0);
if VarIsNull(SProp.Get_Value)
then Result := ''
else Result := SProp.Get_Value;
end;
except
result := '';
end;
end; |
Partager