Share via


ConnectionOptions.Authentication Proprietà

Definizione

Ottiene o imposta il livello di autenticazione COM da utilizzare per le operazioni in questa connessione.

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

Valore della proprietà

Restituisce un valore di enumerazione AuthenticationLevel che indica il livello di autenticazione COM utilizzato per una connessione al computer locale o a un computer remoto.

Esempio

Nell'esempio seguente viene eseguita la connessione a un computer remoto e vengono visualizzate informazioni sul sistema operativo nel computer remoto. Viene ConnectionOptions creato un oggetto per connettersi al computer remoto con le opzioni di connessione desiderate.

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

Commenti

In Windows 2000 e versioni successive, il servizio WMI richiederà l'autenticazione a livello di connessione, mentre in Windows XP e versioni successive richiederà l'autenticazione a livello di pacchetto. Se il client richiede un'impostazione di autenticazione specifica, questa proprietà può essere usata per controllare il livello di autenticazione in questa determinata connessione. Ad esempio, la proprietà può essere impostata su AuthenticationLevel.PacketPrivacy se il client richiede la crittografia di tutte le comunicazioni.

Valore della proprietà

Livello di autenticazione COM da utilizzare per le operazioni in questa connessione. Il valore predefinito è AuthenticationLevel.Unchanged, che indica che il client userà il livello di autenticazione richiesto dal server, in base al processo di negoziazione DCOM standard.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a

Vedi anche