オブジェクトのメソッドを呼び出します。
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 オーバーロードの一覧