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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| function GetWMIExecQuery(wmiServices : ISWbemServices; wmiHost, wmiClass, wmiProperty : string):variant;
var
varArray : variant;
SObject : ISWbemObject;
ObjSet : ISWbemObjectSet;
SProp : ISWbemProperty;
Enum : IEnumVariant;
Value : Cardinal;
TempObj : OleVariant;
i : integer;
wmiTmpProperty : string;
numProperties : integer;
HighBound : integer;
begin
i := 1;
HighBound := 0;
numProperties := 0;
i := 1;
varArray := VarArrayCreate([0, NbOfWord(wmiProperty), 0, 0], varVariant);
while i <= Length(wmiProperty) do
begin
while (wmiProperty[i] <> ';') and (i <= Length(wmiProperty)) do
begin
wmiTmpProperty := wmiTmpProperty + wmiProperty[i];
inc(i);
end;
try
ObjSet := wmiServices.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(wmiTmpProperty, 0);
if numProperties = 0 then
VarArrayRedim(varArray, VarArrayHighBound(varArray, 2) + 1);
if not VarIsNull(SProp.Get_Value) then
begin
varArray[numProperties, HighBound] := Trim(SProp.Get_Value);
end else
varArray[numProperties, HighBound] := '';
inc(HighBound);
end;
except
on e: Exception do
begin
ShowMessage(e.Message);
Exit;
end;
end;
inc(numProperties);
inc(i);
wmiTmpProperty := '';
HighBound := 0;
end;
result := varArray;
VarArrayRedim(varArray, 0);
end; |
Partager