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

后端 未结 1 1259
无人共我
无人共我 2021-01-25 09:58

The title is a bit long but i will try to explain: i\'m trying to connect from one machine (which is connected to a domain) to another machine which also connected to a domain b

相关标签:
1条回答
  • 2021-01-25 10:23

    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);
                    }
                }
            }
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题