Ver Mensaje Individual
  #5  
Antiguo 16-09-2020
elrayo76 elrayo76 is offline
Miembro
 
Registrado: ene 2004
Ubicación: En la tierra, por eso mis archivos en la tierra y no en la nuebe...
Posts: 305
Reputación: 23
elrayo76 Va camino a la fama
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
  // Verifica si el componente está activo. Sale del método si se cuemple la condición.
  objGuard.CheckFalse(aWMIComponent.Active, ERR_CARBON_COMPONENT_ACTIVATED);

  // Instancia de la clase.
  objWMIObject := TWMIUtils.GetClassInstance(aWMIComponent.WMIServices, aInstanceProp, aInstanceValue, aWMIComponent.WMIClass);

  // No se encontró.
  if not Assigned(objWMIObject) then
  begin
    // Preparar el método.
    objWMIMethod := objWMIObject.Methods_.Item(AMethodName, 0);  // Acá es donde recibe el método que tiene que ejecutar.
    objWMInParams := objWMIMethod.InParameters;
    objWMIOutParams := objWMIMethod.OutParameters;

    // ¿Es un parámetro de entrada?.
    if Assigned(objWMInParams) then
    begin
      objWMInParams.Properties_.Get_Count;
      objWMInstance := objWMInParams.SpawnInstance_(0);
      objWMInParams.Properties_.Get_Count;

      // Recorre el array con los nombres de los parámetros.
      for i := 0 to Length(aParamNameArray) - 1 do
      begin
        // Valida el tipo del parámetro entrada/salida.
        if aParamTypeArray[i] = ptIn then
        begin
          // Acá carga los nombres y tipo de datos de los parámetros...

          objWMIProperty := objWMInstance.Properties_.Add(aParamNameArray[i], aParamDataTypeArray[i], False, 0);



          // En este lugar carga los valores de los parámetros...
          // ¿Que pasa si alguno de los parametros a cargar el del tipo ARRAY y no un simple valor?.

          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;

    // Recupera los parámetros de salida.
    if Assigned(objWMIOutParams) then
    begin
      objWMIOutParams.Properties_.Get_Count;
      objWMInstance := objWMIOutParams.SpawnInstance_(0);

      // Recorre el array con los nombres de los parámetros.
      for i := 0 to Length(aParamNameArray) - 1 do
      begin
        // Si es un parámetro de salida.
        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
__________________
Si tienes una función o procedimiento con diez parámetros, probablemente hayas olvidado uno
Responder Con Cita