正确使用RegistryKey.OpenRemoteBaseKey方法C#

发布于 2024-10-10 10:17:20 字数 1278 浏览 1 评论 0原文

摘要:

我需要使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你的星星会说话 2024-10-17 10:17:20
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
        {
        }
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
        {
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文