ConnectionOptions.Impersonation Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il livello di rappresentazione COM da utilizzare per le operazioni in questa connessione.
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
Valore della proprietà
Restituisce un ImpersonationLevel valore di enumerazione che indica il livello di rappresentazione utilizzato per connettersi a WMI.
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.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
Commenti
L'impostazione ImpersonationLevel.Impersonate è vantaggiosa quando il provider è un'applicazione o un servizio attendibile. Elimina la necessità del provider di eseguire l'identità client e i controlli di accesso per le operazioni richieste. Tuttavia, se per qualche motivo il provider non può essere considerato attendibile, consentendogli di rappresentare il client può costituire una minaccia per la sicurezza. In questi casi, è consigliabile impostare questa proprietà dal client su un valore inferiore, ad esempio ImpersonationLevel.Identify. Si noti che ciò può causare un errore del provider per eseguire le operazioni richieste, per mancanza di autorizzazioni sufficienti o impossibilità di eseguire i controlli di accesso.
Valore della proprietà
Livello di rappresentazione COM da utilizzare per le operazioni in questa connessione. Il valore predefinito è ImpersonationLevel.Impersonate, che indica che il provider WMI può rappresentare il client durante l'esecuzione delle operazioni richieste in questa connessione.
Sicurezza di .NET Framework
Attendibilità totale per il chiamante immediato. Questo membro non può essere utilizzato da codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.