如何阅读远程注册表键? [英] How to Read Remote Registry Keys?

查看:103
本文介绍了如何阅读远程注册表键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从远程计算机列表的特定注册表项来读取值。
我可以用下面的code本地做到这一点。

I need to be able to read the values in a specific Registry Key from a list of Remote Computers. I can do this locally with the following code

   using Microsoft.Win32;

        RegistryKey rkey = Registry.LocalMachine;
        RegistryKey rkeySoftware=rkey.OpenSubKey("Software");
        RegistryKey rkeyVendor = rkeySoftware.OpenSubKey("VendorName");
        RegistryKey rkeyVersions = rkeyVendor.OpenSubKey("Versions");

        String[] ValueNames = rkeyVersions.GetValueNames();
        foreach (string name in ValueNames)
        {
          MessageBox.Show(name + ": " + rkeyVersions.GetValue(name).ToString());
        }

但我不知道如何获得远程计算机相同的信息。我是不是即使使用正确的方法或我应该看WMI或其他什么东西?

but I don't know how to get the same info for a Remote Computer. Am I even using the right approach or should I be looking at WMI or something else?

推荐答案

您可以通过WMI,您正在使用做到这一点,但我想你也可以通过相同的机制实现它(即Microsoft.Win32命名空间类)

You can achieve this through WMI, although I think you can also achieve it via the same mechanism (i.e. Microsoft.Win32 namespace classes) that you're currently using.

您需要考虑的:

OpenRemoteBaseKey方法

上面的链接提供了范例。它应该像下面的简单:

The link above gives examples. It's should be as simple as something like:

// Open HKEY_CURRENT_USER\Environment 
// on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(
                   RegistryHive.CurrentUser, remoteName).OpenSubKey(
                   "Environment");

请注意,虽然,会会有打开远程注册表项安全隐患,所以你可能需要确保您有相关的安全权限做到这一点。对于这一点,你要考虑的:

Note, though, that'll there will be security implications in opening remote registry keys, so you may need to ensure that you have the relevant security permissions to do this. For that, you'll want to look into the:

<一个href=\"http://msdn.microsoft.com/en-us/library/system.security.permissions.securitypermission.aspx\">SecurityPermission

<一个href=\"http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission.aspx\">RegistryPermission

System.Security.Permissions 命名空间的类。

这篇关于如何阅读远程注册表键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆