InvokeMethodOptions 类

定义

指定用于调用管理方法的选项。Specifies options for invoking a management method.

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 的新进程。The following example invokes the Win32_Process::Create method to start a new process of Calc.exe. InvokeMethodOptions类用于调用方法。The InvokeMethodOptions class is used to invoke the method.

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[]) 类的新实例。Initializes a new instance of the InvokeMethodOptions class for the InvokeMethod(String, Object[]) operation, using default values. 这是无参数构造函数。This is the parameterless constructor.

InvokeMethodOptions(ManagementNamedValueCollection, TimeSpan)

使用指定的值,为调用操作初始化 InvokeMethodOptions 类的新实例。Initializes a new instance of the InvokeMethodOptions class for an invoke operation using the specified values.

属性

Context

获取或设置一个 WMI 上下文对象。Gets or sets a WMI context object. 这是将传递给 WMI 提供程序的名称-值对列表,该提供程序支持自定义操作的上下文信息。This is a name-value pairs list to be passed through to a WMI provider that supports context information for customized operation.

(继承自 ManagementOptions)
Timeout

获取或设置要应用于该操作的超时。Gets or sets the time-out to apply to the operation. 注意,对于返回集合的操作,此超时将通过结果集合(而不是操作本身)应用于枚举(对于后面一种情况,应使用 ReturnImmediately 属性)。Note that for operations that return collections, this time-out applies to the enumeration through the resulting collection, not the operation itself (the ReturnImmediately property is used for the latter). 此属性用来指示将以半同步方式执行操作。This property is used to indicate that the operation should be performed semi-synchronously.

(继承自 ManagementOptions)

方法

Clone()

返回对象的一个副本。Returns a copy of the object.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于