如何通过openremotebasekey获取远程计算机的注册表内容

linton 2010-09-13 01:07:20
如何通过openremotebasekey获取远程计算机的注册表内容
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mjjkyy1990 2012-10-24
  • 打赏
  • 举报
回复
同问同问
mjjkyy1990 2012-10-24
  • 打赏
  • 举报
回复
我也遇到同样问题了,有人回答吗?百度上也找不到诶
linton 2010-09-13
  • 打赏
  • 举报
回复
RegistryKey environmentKey;
environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine , "192.168.0.1");
//environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine , "\\192.168.0.1");

用第一种方法,不能获取值,用底下注释代码,则提示“找不到网络路径”
gongsun 2010-09-13
  • 打赏
  • 举报
回复

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_CURRENT_USER\Environment
// on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(
RegistryHive.CurrentUser, remoteName).OpenSubKey(
"Environment");
}
catch(IOException e)
{
Console.WriteLine("{0}: {1}",
e.GetType().Name, e.Message);
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();
}
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧