accessing a remote registry with local credentials (of the remote machine) on the domain

本小妞迷上赌 提交于 2019-12-02 06:07:52
Rainer Schaack

I found a nice class for that purpose here at SO: https://stackoverflow.com/a/1197430/4547223

I wrote a quick sample with this class with success:

...
using Microsoft.Win32;
using System.Net;
...

string hostName = 192.168.1.1;

using (new NetworkConnection(@"\\" + hostName + @"\admin$", new NetworkCredential(@"ad\administrator", "TopSecret")))
{
    using (RegistryKey remoteHklm = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, hostName))
    {
        using (RegistryKey serviceKey = remoteHklm.OpenSubKey("System\\CurrentControlSet\\Services", true))
        {
            if (serviceKey != null)
            {
                foreach (string key in serviceKey.GetSubKeyNames())
                {
                    Console.WriteLine(key);
                }
            }
        }

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!