ConnectionOptions.Authentication 属性

定义

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

public:
 property System::Management::AuthenticationLevel Authentication { System::Management::AuthenticationLevel get(); void set(System::Management::AuthenticationLevel value); };
public System.Management.AuthenticationLevel Authentication { get; set; }
member this.Authentication : System.Management.AuthenticationLevel with get, set
Public Property Authentication As AuthenticationLevel

属性值

AuthenticationLevel

返回 AuthenticationLevel 枚举值,该值指示连接到本地或远程计算机时使用的 COM 身份验证级别。Returns an AuthenticationLevel enumeration value indicating the COM authentication level used for a connection to the local or a remote computer.

示例

以下示例连接到远程计算机,并显示有关远程计算机上的操作系统的信息。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 the desired 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();
        options.Authentication =
            System.Management.AuthenticationLevel.PacketPrivacy;

        // 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
        options.Authentication = 6
        ' System.Management.AuthenticationLevel.PacketPrivacy = 6

        ' 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

注解

在 Windows 2000 及更低版本上,WMI 服务将请求连接级别的身份验证,而在 Windows XP 和更高版本中,它将请求数据包级身份验证。On Windows 2000 and below, the WMI service will request Connect level authentication, while on Windows XP and higher it will request Packet level authentication. 如果客户端需要特定身份验证设置,则可以使用此属性来控制此特定连接上的身份验证级别。If the client requires a specific authentication setting, this property can be used to control the authentication level on this particular connection. 例如, AuthenticationLevel.PacketPrivacy 如果客户端要求对所有通信进行加密,则可以将属性设置为。For example, the property can be set to AuthenticationLevel.PacketPrivacy if the client requires all communication to be encrypted.

属性值Property Value

要用于此连接中的操作的 COM 身份验证级别。The COM authentication level to be used for operations in this connection. 默认值为 AuthenticationLevel.Unchanged ,指示客户端将根据标准 DCOM 协商过程使用服务器请求的身份验证级别。The default value is AuthenticationLevel.Unchanged, which indicates that the client will use the authentication level requested by the server, according to the standard DCOM negotiation process.

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

适用于

另请参阅