从远程计算机访问Vista注册表 [英] Accessing Vista Registry from a Remote Machine

查看:81
本文介绍了从远程计算机访问Vista注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从域中的XPSP2计算机访问属于工作组的Vista计算机上的注册表.两台机器都位于更广域网的本地子网上.通过在Vista机器上执行以下操作,我已获得部分访问权限.

  • 启动远程注册表服务并将其设置为自动.
  • 启用文件和打印机共享以及远程桌面
  • 从计算机,属性,远程启用远程桌面.
但是,当我在XPSP2计算机上使用regedit访问Vista计算机时:
  • 我只能看到HKEY_LOCAL_MACHINE和HKEY_USERS键.
  • 我可以访问和编辑HKEY_USERS中和下面的值.
  • 当我尝试访问HKEY_LOCAL_MACHINE时,我得到了出现以下错误:

无法打开HKEY_LOCAL_MACHINE:打开密钥时出错.

解决方案

<这里是一个C#控制台应用程序,它应该可以工作. (它确实适用于查询另一台XPSP2计算机.)当我查询按上述配置的Vista计算机时,出现以下异常:

System.Security.SecurityException:不允许请求的注册表访问.
System.ThrowHelper.ThrowSecurityException(ExceptionResource资源)
在Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称,布尔型可写)
在Microsoft.Win32.RegistryKey.OpenSubKey(字符串名称)
在RemoteKey.Main( <目录> \ Program.cs:第36行中的String [] args)失败的程序集区域为:
MyComputer

下面是代码,第36行以粗体显示.这是根据RegistryHive枚举 MSDN主题.

使用系统;



类RemoteKey
字符串remoteName;

//检查
//程序被调用.
i f(args.Length == 0)
{
Console.WriteLine("Error:远程"+

已调用.") ;
return;
}
其他

}

{
//在远程计算机.
environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,remoteName) ;

}
Console.WriteLine(ex.ToString() );
return;
}
Console.WriteLine("\ n有{0}值for {1}.",
environmentKey.ValueCount .ToString(),
environmentKey.Name);
foreach(environmentKey.GetValueNames()中的字符串valueName )
{
Console.WriteLine("{0,-20}:{1}" ,valueName,
environmentKey.GetValue(valueName). ToString());
}

environmentKey.Close();
}
}


I'm trying to access the registry on a Vista machine that is part of a work group from an XPSP2 machine that is part of a domain. Both machines are on a local subnet of a wider LAN. I have acquired partial access by doing the following on the Vista machine.

  • Starting the Remote Registry Service and setting it to Automatic.
  • Enabling the File and Printer sharing and Remote Desktop groups in the Firewall.
  • Enabling Remote Desktop from Computer, Properties, Remote.
However, when I use regedit on the XPSP2 machine to access the Vista machine:
  • I can see only the HKEY_LOCAL_MACHINE and HKEY_USERS keys.
  • I can access and edit values in and under HKEY_USERS.
  • When I try to access HKEY_LOCAL_MACHINE, I get the following error:

Cannot open HKEY_LOCAL_MACHINE: Error while opening key.

解决方案

Here is a C# console application that should work. (It does work for querying another XPSP2 machine.) When I query a Vista machine configured as above, I get the following exception:

System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
at RemoteKey.Main(String[] args) in <directory>\Program.cs:line 36
The Zone of the assembly that failed was:
MyComputer

Here's the code, with line 36 in bold. This was adapted from the code example in the RegistryHive Enumeration MSDN topic.

using System;
using System.IO;
using System.Security.Permissions;
using Microsoft.Win32;

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
Read = @"HKEY_CURRENT_USER\Environment")]
[assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum,
UnmanagedCode = true)]

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_LOCAL_MACHINE/SOFTWARE on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, remoteName);
environmentKey = environmentKey.OpenSubKey("SOFTWARE");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
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();
}
}


这篇关于从远程计算机访问Vista注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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