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,用來處理非同步 (Asynchronous) 執行的進度和結果。

methodName
String

要執行的方法名稱。

inParameters
ManagementBaseObject

ManagementBaseObject,含有方法的輸入參數。

options
InvokeMethodOptions

InvokeMethodOptions,含有用來執行方法的其他選項。

備註

方法會叫用指定的方法執行,然後傳回 。 進度和結果會透過 上的 ManagementOperationObserver 事件來報告。

.NET Framework 安全性

完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式碼的程式庫

適用於