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 提供者 (Provider),支援自訂作業的內容資訊。

(繼承來源 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)

適用於