如何通过openremotebasekey获取远程计算机的注册表内容
解决方案 »
- 已经定义了一个具有相同参数类型的名为"OnInit"和"InitializeComponent"的成员
- 问题:实例化一个类所需要的时间是否和该类的大小有关系?
- c#窗体如何像QQ那样贴边隐藏
- 在dataset中查询时,没有查询到结果怎么办?
- C# 删除Excel出现的问题
- 关于利用C#实现zip压缩/解压缩的问题
- Winform:动态增加TextBox控件,如何取值!!急呀!!!在线等(注明:在同一类中)
- C# 操作excel 如何全选并添加边框?
- 帮帮我看看代码
- 求助,请问哪位有c#仿windows 7桌面、任务栏、桌面图标的源码?
- C# 调用多个摄像头问题!
- 打包时出现问题:“C:\WINDOWS\system32\msiexec.exe”受到“Windows 系统文件保护”
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();
}
}
environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine , "192.168.0.1");
//environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine , "\\192.168.0.1");用第一种方法,不能获取值,用底下注释代码,则提示“找不到网络路径”