ManagementObject.InvokeMethod 方法

定义

对对象调用方法。Invokes a method on the object.

重载

InvokeMethod(String, Object[])

对对象调用方法。Invokes a method on the object.

InvokeMethod(ManagementOperationObserver, String, Object[])

对对象异步调用方法。Invokes a method on the object, asynchronously.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

对 WMI 对象调用方法。Invokes a method on the WMI object. 输入和输出参数表示为 ManagementBaseObject 对象。The input and output parameters are represented as ManagementBaseObject objects.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

对对象异步调用方法。Invokes a method on the object, asynchronously.

InvokeMethod(String, Object[])

对对象调用方法。Invokes a method on the object.

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

要执行的方法的名称。The name of the method to execute.

args
Object[]

包含参数值的数组。An array containing parameter values.

返回

该方法返回的对象值。The object value returned by the method.

示例

下面的示例调用Win32_Process:: Create方法来启动 notepad.exe 的新进程。The following example invokes the Win32_Process::Create method to start a new process of 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

注解

如果该方法是静态的,则执行仍应成功。If the method is static, the execution should still succeed.

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

InvokeMethod(ManagementOperationObserver, String, Object[])

对对象异步调用方法。Invokes a method on the object, asynchronously.

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

要接收操作结果的对象。The object to receive the results of the operation.

methodName
String

要执行的方法的名称。The name of the method to execute.

args
Object[]

包含参数值的数组。An array containing parameter values.

注解

如果该方法是静态的,则执行仍应成功。If the method is static, the execution should still succeed.

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)

对 WMI 对象调用方法。Invokes a method on the WMI object. 输入和输出参数表示为 ManagementBaseObject 对象。The input and output parameters are represented as ManagementBaseObject objects.

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

要执行的方法的名称。The name of the method to execute.

inParameters
ManagementBaseObject

保存方法的输入参数的 ManagementBaseObjectA ManagementBaseObject holding the input parameters to the method.

options
InvokeMethodOptions

一个 InvokeMethodOptions,它包含有关执行方法的附加选项。An InvokeMethodOptions containing additional options for the execution of the method.

返回

一个 ManagementBaseObject,它包含执行的方法的输出参数和返回值。A ManagementBaseObject containing the output parameters and return value of the executed method.

示例

下面的示例调用Win32_Process:: Create方法来启动 Calc 的新进程。The following example invokes the Win32_Process::Create method to start a new process of 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 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)

对对象异步调用方法。Invokes a method on the object, asynchronously.

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,它用于处理异步执行的进度和结果。A ManagementOperationObserver used to handle the asynchronous execution's progress and results.

methodName
String

要执行的方法的名称。The name of the method to be executed.

inParameters
ManagementBaseObject

包含方法的输入参数的 ManagementBaseObjectA ManagementBaseObject containing the input parameters for the method.

options
InvokeMethodOptions

包含执行方法时使用的附加选项的 InvokeMethodOptionsAn InvokeMethodOptions containing additional options used to execute the method.

注解

方法调用指定的方法执行,然后返回。The method invokes the specified method execution and then returns. 进度和结果通过 ManagementOperationObserver上的事件报告。Progress and results are reported through events on the ManagementOperationObserver.

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

适用于