Paso el código del método que tengo en mi clase genérico que tengo en mi clase para ejecutar cualquier método de los de WMI.
Código Delphi
[-]
var
objWMIObject: ISWbemObject;
objWMIMethod: SWbemMethod;
objWMIProperty: SWbemProperty;
objWMIProp: ISWbemProperty;
objWMInstance: ISWbemObject;
objWMInParams: ISWbemObject;
objWMIOutParams: ISWbemObject;
olePropValue: OleVariant;
i: Integer;
strParamName: String;
begin
objGuard.CheckFalse(aWMIComponent.Active, ERR_CARBON_COMPONENT_ACTIVATED);
objWMIObject := TWMIUtils.GetClassInstance(aWMIComponent.WMIServices, aInstanceProp, aInstanceValue, aWMIComponent.WMIClass);
if not Assigned(objWMIObject) then
begin
objWMIMethod := objWMIObject.Methods_.Item(AMethodName, 0); objWMInParams := objWMIMethod.InParameters;
objWMIOutParams := objWMIMethod.OutParameters;
if Assigned(objWMInParams) then
begin
objWMInParams.Properties_.Get_Count;
objWMInstance := objWMInParams.SpawnInstance_(0);
objWMInParams.Properties_.Get_Count;
for i := 0 to Length(aParamNameArray) - 1 do
begin
if aParamTypeArray[i] = ptIn then
begin
objWMIProperty := objWMInstance.Properties_.Add(aParamNameArray[i], aParamDataTypeArray[i], False, 0);
if aParamDataTypeArray[i] = wbemCimtypeObject then
olePropValue := null
else
olePropValue := aParamValueArray[i];
objWMIProperty.Set_Value(olePropValue);
end;
end;
end;
objWMIOutParams := objWMIObject.ExecMethod_(AMethodName, objWMInstance, 0, nil);
strParamName := aParamNameArray[Length(aParamNameArray) - 1];
objWMIProp := objWMIOutParams.Properties_.Item('ReturnValue', 0);
VarClear(olePropValue);
aResult := objWMIProp.Get_Value;
if Assigned(objWMIOutParams) then
begin
objWMIOutParams.Properties_.Get_Count;
objWMInstance := objWMIOutParams.SpawnInstance_(0);
for i := 0 to Length(aParamNameArray) - 1 do
begin
if aParamTypeArray[i] = ptOut then
begin
objWMIProp := objWMIOutParams.Properties_.Item(aParamNameArray[i], 0);
VarClear(olePropValue);
olePropValue := objWMIProp.Get_Value;
aParamValueArray[i] := olePropValue;
end;
end;
end;
end;
Más alla de que a este método los parámetro que le llegan son un array, que eso lo manejo bien. Uno de los items de ese array es otro array y es el que no se como se manda a WMI cada uno de esos items.
Espero que se entienda. Cualquier cosa me preguntas.
Saludos