ManagementObject.InvokeMethod Метод

Определение

Вызывает метод для обработки объекта.

Перегрузки

InvokeMethod(String, Object[])

Вызывает метод для обработки объекта.

InvokeMethod(ManagementOperationObserver, String, Object[])

Вызывает метод для обработки объекта в асинхронном режиме.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Вызывает метод для обработки WMI-объекта. Входные и выходные параметры представлены в виде объектов ManagementBaseObject.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Вызывает метод для обработки объекта в асинхронном режиме.

InvokeMethod(String, Object[])

Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs

Вызывает метод для обработки объекта.

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

Параметры

methodName
String

Имя метода, который необходимо выполнить.

args
Object[]

Массив, в котором содержатся значения параметров.

Возвращаемое значение

Значение объекта, возвращенное методом.

Примеры

В следующем примере вызывается метод Win32_Process::Create для запуска нового процесса 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

Комментарии

Если метод является статическим, выполнение по-прежнему должно быть успешным.

Безопасность платформы .NET Framework

Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в статье Использование библиотек из частично доверенного кода.

Применяется к

InvokeMethod(ManagementOperationObserver, String, Object[])

Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs

Вызывает метод для обработки объекта в асинхронном режиме.

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

Параметры

watcher
ManagementOperationObserver

Объект, принимающий результаты операции.

methodName
String

Имя метода, который необходимо выполнить.

args
Object[]

Массив, в котором содержатся значения параметров.

Комментарии

Если метод является статическим, выполнение по-прежнему должно быть успешным.

Безопасность платформы .NET Framework

Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в статье Использование библиотек из частично доверенного кода.

Применяется к

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs

Вызывает метод для обработки WMI-объекта. Входные и выходные параметры представлены в виде объектов 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

Параметры

methodName
String

Имя метода, который необходимо выполнить.

inParameters
ManagementBaseObject

ManagementBaseObject содержит входные параметры метода.

options
InvokeMethodOptions

InvokeMethodOptions содержит дополнительные параметры выполнения метода.

Возвращаемое значение

ManagementBaseObject содержит выходные параметры и возвращаемое значение выполняемого метода.

Примеры

В следующем примере вызывается метод Win32_Process::Create для запуска нового процесса 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

Комментарии

Безопасность .NET Framework

Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в статье Использование библиотек из частично доверенного кода.

Применяется к

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs
Исходный код:
ManagementObject.cs

Вызывает метод для обработки объекта в асинхронном режиме.

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)

Параметры

watcher
ManagementOperationObserver

ManagementOperationObserver позволяет управлять асинхронной операцией и обрабатывать ее результаты.

methodName
String

Имя выполняемого метода.

inParameters
ManagementBaseObject

ManagementBaseObject содержит входные параметры метода.

options
InvokeMethodOptions

InvokeMethodOptions содержит дополнительные параметры выполнения метода.

Комментарии

Метод вызывает выполнение указанного метода, а затем возвращает . Ход выполнения и результаты передаются с помощью событий в ManagementOperationObserver.

Безопасность платформы .NET Framework

Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в статье Использование библиотек из частично доверенного кода.

Применяется к