Summary:
I need to use RegistryKey.OpenRemoteBaseKey to query remote registry of HKEY_USERS
Full Explain:
I am currently trying to query registries on remote machines. My code of the RegistryKey.OpenRemoteBaseKey Method is below. I know that the "environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, remoteName).OpenSubKey("Environment");" line from the original example at registrykey.openremotebasekey works. However, i need to query HKEY_USERS which would change the statement to RegistryKey environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, remoteName); and this line does not work.
Any help or code samples would be greatly appreciated! I just need to query the HKEY_USERS registry entries on a remote system. Any method will work for me, my code below is only because its the best method i have found so far to get what i want/need. I am open to change :)
开发者_运维技巧 try
{
// Open HKEY_CURRENT_USER\Environment
// on a remote computer.
string remoteName = host;
RegistryKey environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, remoteName);
foreach (string valueName in environmentKey.GetValueNames())
{
string regy = (valueName + environmentKey.GetValue(valueName).ToString());
Output.AppendText(regy + "\n");
}
// Close the registry key.
environmentKey.Close();
}
catch
{
}
List<string> hkey = new List<string>();
try
{
// Open HKEY_USERS
// on a remote computer.
string remoteName = host;
RegistryKey environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, remoteName);
foreach (string subKeyName in environmentKey.GetSubKeyNames())
{
hkey.Add(subKeyName);
}
// Close the registry key.
environmentKey.Close();
}
catch
{
}
精彩评论