ConnectionOptions.Authority 屬性

定義

取得或設定要用來驗證指定使用者的授權。

C#
public string Authority { get; set; }

屬性值

傳回 String,這個字串會定義用於驗證指定使用者的授權。

範例

下列範例會連線到遠端電腦,並顯示遠端電腦上的作業系統相關信息。 會建立 , ConnectionOptions 以使用所需的連線選項連線到遠端電腦。

C#
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();
        options.Authority = "ntlmdomain:DOMAIN";

        // 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"]);
        }
    }
}

備註

屬性必須依照下列方式傳遞:如果它以字串 “Kerberos:” 開頭,則會使用 Kerberos 驗證,而且此屬性應該包含 Kerberos 主體名稱。 例如,

Kerberos:<principal name>  

如果屬性值以字串 「NTLMDOMAIN:“ 開頭,將會使用 NTLM 驗證,而且屬性應該包含 NTLM 功能變數名稱。 例如,

NTLMDOMAIN:<domain name>  

如果屬性為 Null,則會使用 NTLM 驗證,並使用目前使用者的 NTLM 網域。

屬性值

如果不是 null,這個屬性可以包含要取得用戶進行驗證之 Windows NT/Windows 2000 網域的名稱。

.NET Framework 安全性

完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式代碼的連結庫

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1