ManagementObject.InvokeMethod 方法 (System.Management) |
您所在的位置:网站首页 › invokemethod用法 › ManagementObject.InvokeMethod 方法 (System.Management) |
对对象调用方法。 public: System::Object ^ InvokeMethod(System::String ^ methodName, cli::array ^ 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[]包含参数值的数组。 返回 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 安全性对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 从部分受信任的代码使用库。 适用于 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |