InvokeMethodOptions 类

定义

指定用于调用管理方法的选项。

public ref class InvokeMethodOptions : System::Management::ManagementOptions
public class InvokeMethodOptions : System.Management.ManagementOptions
type InvokeMethodOptions = class
    inherit ManagementOptions
Public Class InvokeMethodOptions
Inherits ManagementOptions
继承
InvokeMethodOptions

示例

以下示例调用 Win32_Process::Create 方法来启动Calc.exe的新过程。 类 InvokeMethodOptions 用于调用 方法。

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";

        // Method Options
        InvokeMethodOptions methodOptions = new
            InvokeMethodOptions(null,
            System.TimeSpan.MaxValue);

        // Execute the method
        ManagementBaseObject outParams =
            processClass.InvokeMethod("Create",
            inParams, methodOptions);

        // 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("root\CIMV2", _
            "Win32_Process", _
            Nothing)

        ' Get an input parameters object for this method
        Dim inParams As ManagementBaseObject = _
            processClass.GetMethodParameters("Create")

        ' Fill in input parameter values
        inParams("CommandLine") = "calc.exe"

        ' Method Options
        Dim methodOptions As New InvokeMethodOptions( _
            Nothing, System.TimeSpan.MaxValue)

        ' Execute the method
        Dim outParams As ManagementBaseObject = _
            processClass.InvokeMethod( _
            "Create", inParams, methodOptions)

        ' 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

构造函数

InvokeMethodOptions()

使用默认值,为 InvokeMethodOptions 操作初始化 InvokeMethod(String, Object[]) 类的新实例。 这是无参数构造函数。

InvokeMethodOptions(ManagementNamedValueCollection, TimeSpan)

使用指定的值,为调用操作初始化 InvokeMethodOptions 类的新实例。

属性

Context

获取或设置一个 WMI 上下文对象。 这是将传递给 WMI 提供程序的名称-值对列表,该提供程序支持自定义操作的上下文信息。

(继承自 ManagementOptions)
Timeout

获取或设置要应用于该操作的超时。 注意,对于返回集合的操作,此超时将通过结果集合(而不是操作本身)应用于枚举(对于后面一种情况,应使用 ReturnImmediately 属性)。 此属性用来指示将以半同步方式执行操作。

(继承自 ManagementOptions)

方法

Clone()

返回对象的一个副本。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于