ManagementObject.InvokeMethod Metoda

Definice

Vyvolá metodu objektu.

Přetížení

Name Description
InvokeMethod(String, Object[])

Vyvolá metodu objektu.

InvokeMethod(ManagementOperationObserver, String, Object[])

Vyvolá metodu objektu asynchronně.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Vyvolá metodu objektu WMI. Vstupní a výstupní parametry jsou reprezentovány jako ManagementBaseObject objekty.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Vyvolá metodu objektu asynchronně.

InvokeMethod(String, Object[])

Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs

Vyvolá metodu objektu.

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

Název metody, která se má provést.

args
Object[]

Pole obsahující hodnoty parametrů.

Návraty

Hodnota objektu vrácená metodou.

Příklady

Následující příklad vyvolá Win32_Process::Create metoda, která spustí nový 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

Poznámky

Pokud je metoda statická, spuštění by mělo být stále úspěšné.

Zabezpečení rozhraní .NET Framework

Plný vztah důvěryhodnosti pro okamžitého volajícího. Tento člen nemůže být používán částečně důvěryhodným kódem. Další informace naleznete v tématu Použití knihoven z částečně důvěryhodného kódu.

Platí pro

InvokeMethod(ManagementOperationObserver, String, Object[])

Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs

Vyvolá metodu objektu asynchronně.

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

Objekt, který má přijímat výsledky operace.

methodName
String

Název metody, která se má provést.

args
Object[]

Pole obsahující hodnoty parametrů.

Poznámky

Pokud je metoda statická, spuštění by mělo být stále úspěšné.

Zabezpečení rozhraní .NET Framework

Plný vztah důvěryhodnosti pro okamžitého volajícího. Tento člen nemůže být používán částečně důvěryhodným kódem. Další informace naleznete v tématu Použití knihoven z částečně důvěryhodného kódu.

Platí pro

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs

Vyvolá metodu objektu WMI. Vstupní a výstupní parametry jsou reprezentovány jako ManagementBaseObject objekty.

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

Název metody, která se má provést.

inParameters
ManagementBaseObject

A ManagementBaseObject holding the input parameters to the method.

options
InvokeMethodOptions

Obsahuje InvokeMethodOptions další možnosti pro spuštění metody.

Návraty

A ManagementBaseObject obsahující výstupní parametry a návratovou hodnotu spuštěné metody.

Příklady

Následující příklad vyvolá Win32_Process::Create metoda, která spustí nový 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

Poznámky

Zabezpečení rozhraní .NET Framework

Plný vztah důvěryhodnosti pro okamžitého volajícího. Tento člen nemůže být používán částečně důvěryhodným kódem. Další informace naleznete v tématu Použití knihoven z částečně důvěryhodného kódu.

Platí pro

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs
Zdroj:
ManagementObject.cs

Vyvolá metodu objektu asynchronně.

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

Slouží ManagementOperationObserver ke zpracování průběhu a výsledků asynchronního provádění.

methodName
String

Název metody, která se má provést.

inParameters
ManagementBaseObject

A ManagementBaseObject obsahující vstupní parametry pro metodu.

options
InvokeMethodOptions

Obsahuje InvokeMethodOptions další možnosti použité ke spuštění metody.

Poznámky

Metoda vyvolá zadané spuštění metody a poté vrátí. Průběh a výsledky jsou hlášeny prostřednictvím událostí v ManagementOperationObserversouboru .

Zabezpečení rozhraní .NET Framework

Plný vztah důvěryhodnosti pro okamžitého volajícího. Tento člen nemůže být používán částečně důvěryhodným kódem. Další informace naleznete v tématu Použití knihoven z částečně důvěryhodného kódu.

Platí pro