ConnectionOptions 类

定义

指定生成 WMI 连接所需的所有设置。Specifies all settings required to make a WMI connection.

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

示例

以下示例连接到远程计算机,并显示有关远程计算机上的操作系统的信息。The following example connects to a remote computer and displays information about the operating system on the remote computer. 创建 ConnectionOptions 以使用默认连接选项连接到远程计算机。A ConnectionOptions is created to connect to the remote computer with default connection options.

using System;
using System.Management;
public class RemoteConnect 
{
    public static void Main() 
    {
        // Build an options object for the remote connection
        // if you plan to connect to the remote
        // computer with a different user name
        // and password than the one you are currently using.
        // This example uses the default values. 
          
        ConnectionOptions options = 
            new ConnectionOptions();
                 
        // Make a connection to a remote computer.
        // Replace the "FullComputerName" section of the
        // string "\\\\FullComputerName\\root\\cimv2" with
        // the full computer name or IP address of the
        // remote computer.
        ManagementScope scope = 
            new ManagementScope(
            "\\\\FullComputerName\\root\\cimv2", options);
        scope.Connect();

        //Query system for Operating System information
        ObjectQuery query = new ObjectQuery(
            "SELECT * FROM Win32_OperatingSystem");
        ManagementObjectSearcher searcher = 
            new ManagementObjectSearcher(scope,query);

        ManagementObjectCollection queryCollection = searcher.Get();
        foreach ( ManagementObject m in queryCollection)
        {
            // Display the remote computer information
            Console.WriteLine("Computer Name : {0}", 
                m["csname"]);
            Console.WriteLine("Windows Directory : {0}", 
                m["WindowsDirectory"]);
            Console.WriteLine("Operating System: {0}",  
                m["Caption"]);
            Console.WriteLine("Version: {0}", m["Version"]);
            Console.WriteLine("Manufacturer : {0}", 
                m["Manufacturer"]);
        }
    }
}
Imports System.Management
Public Class RemoteConnect

    Public Overloads Shared Function Main( _
    ByVal args() As String) As Integer

        ' Build an options object for the remote connection
        ' if you plan to connect to the remote
        ' computer with a different user name
        ' and password than the one you are currently using
        Dim options As ConnectionOptions
        options = New ConnectionOptions

        ' Make a connection to a remote computer.
        ' Replace the "FullComputerName" section of the
        ' string "\\FullComputerName\root\cimv2" with
        ' the full computer name or IP address of the
        ' remote computer.
        Dim scope As ManagementScope
        scope = New ManagementScope( _
            "\\FullComputerName\root\cimv2", options)
        scope.Connect()

        ' Query system for Operating System information
        Dim query As ObjectQuery
        query = New ObjectQuery( _
            "SELECT * FROM Win32_OperatingSystem")
        Dim searcher As ManagementObjectSearcher
        searcher = _
            New ManagementObjectSearcher(scope, query)

        Dim queryCollection As ManagementObjectCollection
        queryCollection = searcher.Get()

        Dim m As ManagementObject
        For Each m In queryCollection
            ' Display the remote computer information
            Console.WriteLine("Computer Name : {0}", _
                m("csname"))
            Console.WriteLine("Windows Directory : {0}", _
                m("WindowsDirectory"))
            Console.WriteLine("Operating System: {0}", _
                m("Caption"))
            Console.WriteLine("Version: {0}", m("Version"))
            Console.WriteLine("Manufacturer : {0}", _
                m("Manufacturer"))
        Next

        Return 0
    End Function
End Class

构造函数

ConnectionOptions()

使用默认值,为连接操作初始化 ConnectionOptions 类的新实例。Initializes a new instance of the ConnectionOptions class for the connection operation, using default values. 这就是无参数构造函数。This is the parameterless constructor.

ConnectionOptions(String, String, SecureString, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

创建新的 ConnectionOption。Creates a new ConnectionOption.

ConnectionOptions(String, String, String, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

使用指定的值,初始化将用于 WMI 连接的 ConnectionOptions 类的新实例。Initializes a new instance of the ConnectionOptions class to be used for a WMI connection, using the specified values.

属性

Authentication

获取或设置用于此连接中的操作的 COM 身份验证级别。Gets or sets the COM authentication level to be used for operations in this connection.

Authority

获取或设置将用于验证指定用户的授权。Gets or sets the authority to be used to authenticate the specified user.

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)
EnablePrivileges

获取或设置一个值,该值指示是否需要为连接操作启用用户特权。Gets or sets a value indicating whether user privileges need to be enabled for the connection operation. 只有在执行的操作需要启用某种用户特权(例如,重新启动计算机)时,才应使用此属性。This property should only be used when the operation performed requires a certain user privilege to be enabled (for example, a machine restart).

Impersonation

获取或设置用于此连接中的操作的 COM 模拟级别。Gets or sets the COM impersonation level to be used for operations in this connection.

Locale

获取或设置将用于连接操作的区域设置。Gets or sets the locale to be used for the connection operation.

Password

设置指定用户的密码。Sets the password for the specified user.

SecurePassword

设置指定用户的密码。Sets the password for the specified user.

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)
Username

获取或设置将用于连接操作的用户名。Gets or sets the user name to be used for the connection operation.

方法

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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于