正确使用RegistryKey.OpenRemoteBaseKey方法C#
摘要:
我需要使用RegistryKey.OpenRemoteBaseKey 来查询HKEY_USERS 的远程注册表
完整说明:
我目前正在尝试查询远程计算机上的注册表。我的RegistryKey.OpenRemoteBaseKey方法的代码如下。我知道 “环境密钥=RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser,remoteName).OpenSubKey(“环境”);“ 原始示例中的行 registrykey.openremotebasekey 有效。但是,我需要查询 HKEY_USERS ,这会将语句更改为 RegistryKeyenvironmentKey=RegistryKey.OpenRemoteBaseKey(RegistryHive.Users,remoteName); 这条线不起作用。
任何帮助或代码示例将不胜感激!我只需要查询远程系统上的 HKEY_USERS 注册表项。任何方法都适合我,我下面的代码只是因为它是我迄今为止找到的获得我想要/需要的东西的最佳方法。我愿意改变:)
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
{
}
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
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)