ConnectionOptions.Impersonation Eigenschaft

Definition

Dient zum Abrufen oder Festlegen der COM-Identitätswechselebene, die für Vorgänge in dieser Verbindung verwendet werden soll.

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

Eigenschaftswert

Gibt einen ImpersonationLevel Enumerationswert zurück, der die Identitätswechselebene angibt, die zum Herstellen einer Verbindung mit WMI verwendet wird.

Beispiele

Im folgenden Beispiel wird eine Verbindung mit einem Remotecomputer hergestellt und Informationen zum Betriebssystem auf dem Remotecomputer angezeigt. Es wird eine ConnectionOptions Verbindung mit dem Remotecomputer mit den gewünschten Verbindungsoptionen erstellt.

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.Impersonation =
            System.Management.ImpersonationLevel.Impersonate;

        // 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.Impersonation = 3
        ' System.Management.ImpersonationLevel.Impersonate = 3

        ' 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

Hinweise

Die ImpersonationLevel.Impersonate Einstellung ist vorteilhaft, wenn der Anbieter eine vertrauenswürdige Anwendung oder ein vertrauenswürdiger Dienst ist. Der Anbieter muss keine Clientidentitäts- und Zugriffsüberprüfungen für die angeforderten Vorgänge ausführen. Wenn der Anbieter aus irgendeinem Grund jedoch nicht als vertrauenswürdig eingestuft werden kann, kann die Identität des Clients eine Sicherheitsrisiken darstellen. In solchen Fällen wird empfohlen, dass diese Eigenschaft vom Client auf einen niedrigeren Wert festgelegt wird, z ImpersonationLevel.Identify. B. . Beachten Sie, dass dies dazu führen kann, dass der Anbieter die angeforderten Vorgänge nicht ausführt, weil keine ausreichenden Berechtigungen oder Unfähigkeit zum Ausführen von Zugriffsprüfungen vorhanden sind.

Eigenschaftswert

Die COM-Identitätswechselebene, die für Vorgänge in dieser Verbindung verwendet werden soll. Der Standardwert ist ImpersonationLevel.Impersonate, der angibt, dass der WMI-Anbieter den Client beim Ausführen der angeforderten Vorgänge in dieser Verbindung imitieren kann.

.NET Framework-Sicherheit

Volle Vertrauenswürdigstellung für den unmittelbaren Anrufer. Dieses Element kann nicht von teilweise vertrauenswürdigem Code verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigen Code.

Gilt für: