This documentation is archived and is not being maintained.

ManagementObject.InvokeMethod Method

Invokes a method on the object.

Overload List

Invokes a method on the object.

[Visual Basic] Overloads Public Function InvokeMethod(String, Object()) As Object
[C#] public object InvokeMethod(string, object[]);
[C++] public: Object* InvokeMethod(String*, Object[]);
[JScript] public function InvokeMethod(String, Object[]) : Object;

Invokes a method on the object, asynchronously.

[Visual Basic] Overloads Public Sub InvokeMethod(ManagementOperationObserver, String, Object())
[C#] public void InvokeMethod(ManagementOperationObserver, string, object[]);
[C++] public: void InvokeMethod(ManagementOperationObserver*, String*, Object[]);
[JScript] public function InvokeMethod(ManagementOperationObserver, String, Object[]);

Invokes a method on the WMI object. The input and output parameters are represented as ManagementBaseObject objects.

[Visual Basic] Overloads Public Function InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions) As ManagementBaseObject
[C#] public ManagementBaseObject InvokeMethod(string, ManagementBaseObject, InvokeMethodOptions);
[C++] public: ManagementBaseObject* InvokeMethod(String*, ManagementBaseObject*, InvokeMethodOptions*);
[JScript] public function InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions) : ManagementBaseObject;

Invokes a method on the object, asynchronously.

[Visual Basic] Overloads Public Sub InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)
[C#] public void InvokeMethod(ManagementOperationObserver, string, ManagementBaseObject, InvokeMethodOptions);
[C++] public: void InvokeMethod(ManagementOperationObserver*, String*, ManagementBaseObject*, InvokeMethodOptions*);
[JScript] public function InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions);

Example

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of InvokeMethod. For other examples that might be available, see the individual overload topics.
[C#] 
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"]);
   }
}
   
[Visual Basic] 
Imports System
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
   

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ManagementObject Class | ManagementObject Members | System.Management Namespace

Show: