Share via


ManagementObject.InvokeMethod Metodo

Definizione

Richiama un metodo sull'oggetto.

Overload

InvokeMethod(String, Object[])

Richiama un metodo sull'oggetto.

InvokeMethod(ManagementOperationObserver, String, Object[])

Richiama un metodo sull'oggetto in modo asincrono.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Richiama un metodo sull'oggetto WMI. I parametri di input e output sono rappresentati come oggetti ManagementBaseObject.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Richiama un metodo sull'oggetto in modo asincrono.

InvokeMethod(String, Object[])

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Richiama un metodo sull'oggetto.

public:
 System::Object ^ InvokeMethod(System::String ^ methodName, cli::array <System::Object ^> ^ args);
public object InvokeMethod (string methodName, object[] args);
member this.InvokeMethod : string * obj[] -> obj
Public Function InvokeMethod (methodName As String, args As Object()) As Object

Parametri

methodName
String

Nome del metodo da eseguire.

args
Object[]

Matrice contenente i valori dei parametri.

Restituisce

Valore dell'oggetto restituito dal metodo.

Esempio

Nell'esempio seguente viene richiamato il metodo Win32_Process::Create per avviare un nuovo processo di Notepad.exe.

using System;
using System.Management;

// This sample demonstrates invoking
// a WMI method using an array of arguments.
public class InvokeMethod
{
    public static void Main()
    {

        // Get the object on which the
        // method will be invoked
        ManagementClass processClass =
            new ManagementClass("Win32_Process");

        // Create an array containing all
        // arguments for the method
        object[] methodArgs =
            {"notepad.exe", null, null, 0};

        //Execute the method
        object result =
            processClass.InvokeMethod(
            "Create", methodArgs);

        //Display results
        Console.WriteLine(
            "Creation of process returned: " + result);
        Console.WriteLine("Process id: " + methodArgs[3]);
    }
}
Imports System.Management

' This sample demonstrates invoking a WMI method
' using an array of arguments.
Class InvokeMethod
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        ' Get the object on which the method will be invoked
        Dim processClass As _
            New ManagementClass("Win32_Process")

        ' Create an array containing all arguments 
        ' for the method
        Dim methodArgs() As Object = _
            {"notepad.exe", Nothing, Nothing, 0}

        ' Execute the method
        Dim result As Object = _
            processClass.InvokeMethod("Create", methodArgs)

        ' Display results
        Console.WriteLine( _
            "Creation of process returned: {0}", result)
        Console.WriteLine( _
            "Process id: {0}", methodArgs(3))
        Return 0
    End Function
End Class

Commenti

Se il metodo è statico, l'esecuzione dovrebbe comunque avere esito positivo.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a

InvokeMethod(ManagementOperationObserver, String, Object[])

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Richiama un metodo sull'oggetto in modo asincrono.

public:
 void InvokeMethod(System::Management::ManagementOperationObserver ^ watcher, System::String ^ methodName, cli::array <System::Object ^> ^ args);
public void InvokeMethod (System.Management.ManagementOperationObserver watcher, string methodName, object[] args);
member this.InvokeMethod : System.Management.ManagementOperationObserver * string * obj[] -> unit
Public Sub InvokeMethod (watcher As ManagementOperationObserver, methodName As String, args As Object())

Parametri

watcher
ManagementOperationObserver

Oggetto che riceverà i risultati dell'operazione.

methodName
String

Nome del metodo da eseguire.

args
Object[]

Matrice contenente i valori dei parametri.

Commenti

Se il metodo è statico, l'esecuzione dovrebbe comunque avere esito positivo.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Richiama un metodo sull'oggetto WMI. I parametri di input e output sono rappresentati come oggetti ManagementBaseObject.

public:
 System::Management::ManagementBaseObject ^ InvokeMethod(System::String ^ methodName, System::Management::ManagementBaseObject ^ inParameters, System::Management::InvokeMethodOptions ^ options);
public System.Management.ManagementBaseObject InvokeMethod (string methodName, System.Management.ManagementBaseObject inParameters, System.Management.InvokeMethodOptions options);
member this.InvokeMethod : string * System.Management.ManagementBaseObject * System.Management.InvokeMethodOptions -> System.Management.ManagementBaseObject
Public Function InvokeMethod (methodName As String, inParameters As ManagementBaseObject, options As InvokeMethodOptions) As ManagementBaseObject

Parametri

methodName
String

Nome del metodo da eseguire.

inParameters
ManagementBaseObject

Oggetto ManagementBaseObject contenente i parametri di input al metodo.

options
InvokeMethodOptions

Oggetto InvokeMethodOptions contenente opzioni aggiuntive per l'esecuzione del metodo.

Restituisce

Oggetto ManagementBaseObject contenente i parametri di output e il valore restituito del metodo eseguito.

Esempio

Nell'esempio seguente viene richiamato il metodo Win32_Process::Create per avviare un nuovo processo di Calc.exe.

using System;
using System.Management;

// This sample demonstrates invoking
// a WMI method using parameter objects
public class InvokeMethod
{
    public static void Main()
    {

        // Get the object on which the method will be invoked
        ManagementClass processClass =
            new ManagementClass("Win32_Process");

        // Get an input parameters object for this method
        ManagementBaseObject inParams =
            processClass.GetMethodParameters("Create");

        // Fill in input parameter values
        inParams["CommandLine"] = "calc.exe";

        // Execute the method
        ManagementBaseObject outParams =
            processClass.InvokeMethod ("Create",
            inParams, null);

        // Display results
        // Note: The return code of the method is
        // provided in the "returnValue" property
        // of the outParams object
        Console.WriteLine(
            "Creation of calculator process returned: "
            + outParams["returnValue"]);
        Console.WriteLine("Process ID: "
            + outParams["processId"]);
    }
}
Imports System.Management

' This sample demonstrates invoking
' a WMI method using parameter objects
Class InvokeMethod
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        ' Get the object on which the
        ' method will be invoked
        Dim processClass As _
            New ManagementClass("Win32_Process")

        ' Get an input parameters object for this method
        Dim inParams As ManagementBaseObject = _
            processClass.GetMethodParameters("Create")

        ' Fill in input parameter values
        inParams("CommandLine") = "calc.exe"

        ' Execute the method
        Dim outParams As ManagementBaseObject = _
            processClass.InvokeMethod( _
            "Create", inParams, Nothing)

        ' Display results
        ' Note: The return code of the method 
        ' is provided in the "returnValue" property
        ' of the outParams object
        Console.WriteLine( _
            "Creation of calculator process returned: {0}", _
            outParams("returnValue"))
        Console.WriteLine("Process ID: {0}", _
            outParams("processId"))

        Return 0
    End Function
End Class

Commenti

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Richiama un metodo sull'oggetto in modo asincrono.

public:
 void InvokeMethod(System::Management::ManagementOperationObserver ^ watcher, System::String ^ methodName, System::Management::ManagementBaseObject ^ inParameters, System::Management::InvokeMethodOptions ^ options);
public void InvokeMethod (System.Management.ManagementOperationObserver watcher, string methodName, System.Management.ManagementBaseObject inParameters, System.Management.InvokeMethodOptions options);
member this.InvokeMethod : System.Management.ManagementOperationObserver * string * System.Management.ManagementBaseObject * System.Management.InvokeMethodOptions -> unit
Public Sub InvokeMethod (watcher As ManagementOperationObserver, methodName As String, inParameters As ManagementBaseObject, options As InvokeMethodOptions)

Parametri

watcher
ManagementOperationObserver

Oggetto ManagementOperationObserver utilizzato per gestire lo stato e i risultati dell'esecuzione asincrona.

methodName
String

Nome del metodo da eseguire.

inParameters
ManagementBaseObject

Oggetto ManagementBaseObject contenente i parametri di input per il metodo.

options
InvokeMethodOptions

Oggetto InvokeMethodOptions contenente opzioni aggiuntive utilizzate per eseguire il metodo.

Commenti

Il metodo richiama l'esecuzione del metodo specificata e quindi restituisce . Lo stato di avanzamento e i risultati vengono segnalati tramite eventi in ManagementOperationObserver.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a