ConnectionOptions 类

定义

指定生成 WMI 连接所需的所有设置。

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

示例

以下示例连接到远程计算机,并显示有关远程计算机上的操作系统的信息。 ConnectionOptions创建 以使用默认连接选项连接到远程计算机。

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 类的新实例。 这是无参数构造函数。

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

创建新的 ConnectionOption。

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

使用指定的值,初始化将用于 WMI 连接的 ConnectionOptions 类的新实例。

属性

Authentication

获取或设置用于此连接中的操作的 COM 身份验证级别。

Authority

获取或设置将用于验证指定用户的授权。

Context

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

(继承自 ManagementOptions)
EnablePrivileges

获取或设置一个值,该值指示是否需要为连接操作启用用户特权。 只有在执行的操作需要启用某种用户特权(例如,重新启动计算机)时,才应使用此属性。

Impersonation

获取或设置用于此连接中的操作的 COM 模拟级别。

Locale

获取或设置将用于连接操作的区域设置。

Password

设置指定用户的密码。

SecurePassword

设置指定用户的密码。

Timeout

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

(继承自 ManagementOptions)
Username

获取或设置将用于连接操作的用户名。

方法

Clone()

返回对象的一个副本。

Equals(Object)

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

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

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

(继承自 Object)

适用于