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
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);
}
}
}
}
}