RegistryKey.OpenRemoteBaseKey Metodo
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.
Apre un nuovo T:Microsoft. Win32.RegistryKey che rappresenta la chiave richiesta in un computer remoto, con l'opzione della visualizzazione del Registro di sistema specificata.
Overload
| Nome | Descrizione |
|---|---|
| OpenRemoteBaseKey(RegistryHive, String) |
Apre un nuovo RegistryKey oggetto che rappresenta la chiave richiesta in un computer remoto. |
| OpenRemoteBaseKey(RegistryHive, String, RegistryView) |
Apre una nuova chiave del Registro di sistema che rappresenta la chiave richiesta in un computer remoto con la visualizzazione specificata. |
OpenRemoteBaseKey(RegistryHive, String)
- Origine:
- RegistryKey.cs
Apre un nuovo RegistryKey oggetto che rappresenta la chiave richiesta in un computer remoto.
public:
static Microsoft::Win32::RegistryKey ^ OpenRemoteBaseKey(Microsoft::Win32::RegistryHive hKey, System::String ^ machineName);
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName);
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string -> Microsoft.Win32.RegistryKey
Public Shared Function OpenRemoteBaseKey (hKey As RegistryHive, machineName As String) As RegistryKey
Parametri
- hKey
- RegistryHive
HKEY da aprire dall'enumerazione RegistryHive .
- machineName
- String
Computer remoto.
Valori restituiti
Chiave del Registro di sistema richiesta.
Eccezioni
hKey non è valido.
machineName non viene trovato.
machineName è null.
L'utente non dispone delle autorizzazioni appropriate per eseguire questa operazione.
L'utente non dispone dei diritti del Registro di sistema necessari.
Esempio
Nell'esempio di codice seguente viene illustrato come aprire una chiave del Registro di sistema in un computer remoto ed enumerare i valori della chiave. Il computer remoto deve eseguire il servizio registro remoto. Specificare il nome del computer remoto come argomento della riga di comando quando si richiama il programma.
using namespace System;
using namespace System::IO;
using namespace System::Security::Permissions;
using namespace Microsoft::Win32;
int main( int argc, char *argv[] )
{
RegistryKey ^ environmentKey;
// Check that an argument was specified when the
// program was invoked.
if ( argc == 1 )
{
Console::WriteLine( "Error: The name of the remote computer "
"must be specified as input on the command line." );
return -1;
}
try
{
// Open HKEY_CURRENT_USER\Environment on a remote computer.
environmentKey = RegistryKey::OpenRemoteBaseKey( RegistryHive::CurrentUser, gcnew String(argv[ 1 ]) )->OpenSubKey( "Environment" );
}
catch ( IOException^ e )
{
Console::WriteLine( "{0}: {1}", e->GetType()->Name, e->Message );
return -1;
}
// Print the values.
Console::WriteLine( "\nThere are {0} values for {1}.", environmentKey->ValueCount.ToString(), environmentKey->Name );
array<String^>^valueNames = environmentKey->GetValueNames();
for ( int i = 0; i < environmentKey->ValueCount; i++ )
{
Console::WriteLine( "{0,-20}: {1}", valueNames[ i ], environmentKey->GetValue( valueNames[ i ] )->ToString() );
}
// Close the registry key.
environmentKey->Close();
}
using System;
using System.IO;
using System.Security.Permissions;
using Microsoft.Win32;
class RemoteKey
{
static void Main(string[] args)
{
RegistryKey environmentKey;
string remoteName;
// Check that an argument was specified when the
// program was invoked.
if(args.Length == 0)
{
Console.WriteLine("Error: The name of the remote " +
"computer must be specified when the program is " +
"invoked.");
return;
}
else
{
remoteName = args[0];
}
try
{
// Open HKEY_CURRENT_USER\Environment
// on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(
RegistryHive.CurrentUser, remoteName).OpenSubKey(
"Environment");
}
catch(IOException e)
{
Console.WriteLine("{0}: {1}",
e.GetType().Name, e.Message);
return;
}
// Print the values.
Console.WriteLine("\nThere are {0} values for {1}.",
environmentKey.ValueCount.ToString(),
environmentKey.Name);
foreach(string valueName in environmentKey.GetValueNames())
{
Console.WriteLine("{0,-20}: {1}", valueName,
environmentKey.GetValue(valueName).ToString());
}
// Close the registry key.
environmentKey.Close();
}
}
Imports System.IO
Imports System.Security.Permissions
Imports Microsoft.Win32
Public Class RemoteKey
Shared Sub Main(commandLineArgs As String())
Dim environmentKey As RegistryKey
' Check that an argument was specified when the
' program was invoked.
If commandLineArgs.Length = 0 Then
Console.WriteLine("Error: The name of the remote " & _
"computer must be specified as input on the " & _
"command line.")
Return
End If
Try
' Open HKEY_CURRENT_USER\Environment on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.CurrentUser, _
commandLineArgs(0)).OpenSubKey("Environment")
Catch ex As IOException
Console.WriteLine("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
' Print the values.
Console.WriteLine("\nThere are {0} values For {1}.", _
environmentKey.ValueCount.ToString(), environmentKey.Name)
For Each valueName As String In environmentKey.GetValueNames()
Console.WriteLine("{0,-20}: {1}", valueName, _
environmentKey.GetValue(valueName).ToString())
Next
' Close the registry key.
environmentKey.Close()
End Sub
End Class
Commenti
Il Registro di sistema del computer locale viene aperto se machineName è String.Empty. La chiave richiesta deve essere una chiave radice nel computer remoto ed è identificata dal valore appropriato RegistryHive .
Affinché una chiave venga aperta in remoto, sia il server che i computer client devono eseguire il servizio Registro di sistema remoto e avere l'amministrazione remota abilitata.
Vedi anche
Si applica a
OpenRemoteBaseKey(RegistryHive, String, RegistryView)
- Origine:
- RegistryKey.cs
Apre una nuova chiave del Registro di sistema che rappresenta la chiave richiesta in un computer remoto con la visualizzazione specificata.
public:
static Microsoft::Win32::RegistryKey ^ OpenRemoteBaseKey(Microsoft::Win32::RegistryHive hKey, System::String ^ machineName, Microsoft::Win32::RegistryView view);
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view);
[System.Runtime.InteropServices.ComVisible(false)]
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view);
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string * Microsoft.Win32.RegistryView -> Microsoft.Win32.RegistryKey
[<System.Runtime.InteropServices.ComVisible(false)>]
static member OpenRemoteBaseKey : Microsoft.Win32.RegistryHive * string * Microsoft.Win32.RegistryView -> Microsoft.Win32.RegistryKey
Public Shared Function OpenRemoteBaseKey (hKey As RegistryHive, machineName As String, view As RegistryView) As RegistryKey
Parametri
- hKey
- RegistryHive
HKEY da aprire dall'enumerazione RegistryHive .
- machineName
- String
Computer remoto.
- view
- RegistryView
Visualizzazione del Registro di sistema da utilizzare.
Valori restituiti
Chiave del Registro di sistema richiesta.
- Attributi
Eccezioni
hKey o view non è valido.
machineName non viene trovato.
machineName è null.
L'utente non dispone dei diritti del Registro di sistema necessari.
L'utente non dispone delle autorizzazioni necessarie per eseguire questa operazione.
Commenti
Il Registro di sistema del computer locale viene aperto se machineName è String.Empty. La chiave richiesta deve essere una chiave radice nel computer remoto ed è identificata dal valore appropriato RegistryHive .
Affinché una chiave venga aperta in remoto, sia il server che i computer client devono eseguire il servizio Registro di sistema remoto e avere l'amministrazione remota abilitata.
Nelle versioni a 64 bit di Windows, le parti del Registro di sistema vengono archiviate separatamente per le applicazioni a 32 bit e a 64 bit. È disponibile una visualizzazione a 32 bit per le applicazioni a 32 bit e una visualizzazione a 64 bit per le applicazioni a 64 bit. Se view è Registry64 ma il computer remoto esegue un sistema operativo a 32 bit, la chiave restituita userà la Registry32 visualizzazione.