ManagementObject.InvokeMethod Metoda

Definicja

Wywołuje metodę obiektu.

Przeciążenia

InvokeMethod(String, Object[])

Wywołuje metodę obiektu.

InvokeMethod(ManagementOperationObserver, String, Object[])

Wywołuje metodę w obiekcie asynchronicznie.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Wywołuje metodę w obiekcie WMI. Parametry wejściowe i wyjściowe są reprezentowane jako ManagementBaseObject obiekty.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Wywołuje metodę w obiekcie asynchronicznie.

InvokeMethod(String, Object[])

Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs

Wywołuje metodę obiektu.

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

Parametry

methodName
String

Nazwa metody do wykonania.

args
Object[]

Tablica zawierająca wartości parametrów.

Zwraca

Wartość obiektu zwrócona przez metodę .

Przykłady

Poniższy przykład wywołuje metodę Win32_Process::Twórca, aby rozpocząć nowy proces 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

Uwagi

Jeśli metoda jest statyczna, wykonanie nadal powinno zakończyć się powodzeniem.

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

InvokeMethod(ManagementOperationObserver, String, Object[])

Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs

Wywołuje metodę w obiekcie asynchronicznie.

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())

Parametry

watcher
ManagementOperationObserver

Obiekt do odbierania wyników operacji.

methodName
String

Nazwa metody do wykonania.

args
Object[]

Tablica zawierająca wartości parametrów.

Uwagi

Jeśli metoda jest statyczna, wykonanie nadal powinno zakończyć się powodzeniem.

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs

Wywołuje metodę w obiekcie WMI. Parametry wejściowe i wyjściowe są reprezentowane jako ManagementBaseObject obiekty.

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

Parametry

methodName
String

Nazwa metody do wykonania.

inParameters
ManagementBaseObject

Przytrzymanie ManagementBaseObject parametrów wejściowych do metody .

options
InvokeMethodOptions

Zawiera InvokeMethodOptions dodatkowe opcje wykonywania metody.

Zwraca

Element ManagementBaseObject zawierający parametry wyjściowe i wartość zwracaną metody wykonanej.

Przykłady

Poniższy przykład wywołuje metodę Win32_Process::Twórca, aby rozpocząć nowy proces 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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs
Źródło:
ManagementObject.cs

Wywołuje metodę w obiekcie asynchronicznie.

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)

Parametry

watcher
ManagementOperationObserver

Służy ManagementOperationObserver do obsługi postępu i wyników wykonywania asynchronicznego.

methodName
String

Nazwa metody do wykonania.

inParameters
ManagementBaseObject

Element ManagementBaseObject zawierający parametry wejściowe metody .

options
InvokeMethodOptions

Zawiera InvokeMethodOptions dodatkowe opcje używane do wykonania metody.

Uwagi

Metoda wywołuje wykonanie określonej metody, a następnie zwraca wartość . Postęp i wyniki są raportowane za pośrednictwem zdarzeń w obiekcie ManagementOperationObserver.

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy