I am trying to write a small command line application with C # that will prompt you to enter a username and password that will be used to log in to several remote computers that are on the same network / domain and start a local session.
I tried to connect to a remote computer and request information about the operating system of the remote PC using the following code:
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope(@"\\REMOTE_COMPUTER_NAME");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("Computer Name : {0}", m["csname"]);
Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
Console.WriteLine("Operating System: {0}", m["Caption"]);
Console.WriteLine("Version: {0}", m["Version"]);
Console.WriteLine("Manufacturer : {0}", m["Manufacturer"]);
}
However, this only returns information on the local PC I'm working on, and not on the remote PC.
I do not notice something with this code? And is there a suitable approach to achieve what I'm trying to do?
source
share