ManagementObject.InvokeMethod Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Invokes a method on the object.
Overloads
InvokeMethod(String, Object[]) |
Invokes a method on the object. |
InvokeMethod(ManagementOperationObserver, String, Object[]) |
Invokes a method on the object, asynchronously. |
InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions) |
Invokes a method on the WMI object. The input and output parameters are represented as ManagementBaseObject objects. |
InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions) |
Invokes a method on the object, asynchronously. |
InvokeMethod(String, Object[])
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
Invokes a method on the object.
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
Parameters
- methodName
- String
The name of the method to execute.
- args
- Object[]
An array containing parameter values.
Returns
The object value returned by the method.
Examples
The following example invokes the Win32_Process::Create method to start a new process of 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
Remarks
If the method is static, the execution should still succeed.
.NET Framework Security
Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Applies to
InvokeMethod(ManagementOperationObserver, String, Object[])
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
Invokes a method on the object, asynchronously.
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())
Parameters
- watcher
- ManagementOperationObserver
The object to receive the results of the operation.
- methodName
- String
The name of the method to execute.
- args
- Object[]
An array containing parameter values.
Remarks
If the method is static, the execution should still succeed.
.NET Framework Security
Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Applies to
InvokeMethod(String, ManagementBaseObject, InvokeMethodOptions)
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
Invokes a method on the WMI object. The input and output parameters are represented as ManagementBaseObject objects.
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
Parameters
- methodName
- String
The name of the method to execute.
- inParameters
- ManagementBaseObject
A ManagementBaseObject holding the input parameters to the method.
- options
- InvokeMethodOptions
An InvokeMethodOptions containing additional options for the execution of the method.
Returns
A ManagementBaseObject containing the output parameters and return value of the executed method.
Examples
The following example invokes the Win32_Process::Create method to start a new process of 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
Remarks
.NET Framework Security
Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Applies to
InvokeMethod(ManagementOperationObserver, String, ManagementBaseObject, InvokeMethodOptions)
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
- Source:
- ManagementObject.cs
Invokes a method on the object, asynchronously.
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)
Parameters
- watcher
- ManagementOperationObserver
A ManagementOperationObserver used to handle the asynchronous execution's progress and results.
- methodName
- String
The name of the method to be executed.
- inParameters
- ManagementBaseObject
A ManagementBaseObject containing the input parameters for the method.
- options
- InvokeMethodOptions
An InvokeMethodOptions containing additional options used to execute the method.
Remarks
The method invokes the specified method execution and then returns. Progress and results are reported through events on the ManagementOperationObserver.
.NET Framework Security
Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Applies to
.NET