次の方法で共有


ManagementObject.InvokeMethod メソッド (String, Object )

オブジェクトのメソッドを呼び出します。

Overloads Public Function InvokeMethod( _
   ByVal methodName As String, _   ByVal args() As Object _) As Object
[C#]
public object InvokeMethod(stringmethodName,object[] args);
[C++]
public: Object* InvokeMethod(String* methodName,Object* args __gc[]);
[JScript]
public function InvokeMethod(
   methodName : String,args : Object[]) : Object;

パラメータ

  • methodName
    実行するメソッドの名前。
  • args
    パラメータ値を格納している配列。

戻り値

メソッドが返す値。

解説

メソッドが静的メソッドの場合、その実行は成功します。

使用例

 
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]);
    }

}
   
[Visual Basic] 
Imports System
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
   

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

ManagementObject クラス | ManagementObject メンバ | System.Management 名前空間 | ManagementObject.InvokeMethod オーバーロードの一覧