using System;
using System.Management;
using System.Security;
public class RemoteConnect
{
public static void Main()
{
SecureString pw = new SecureString();
pw.AppendChar('a');
pw.MakeReadOnly();
ConnectionOptions options = new ConnectionOptions("MS_409", "userName", pw,"ntdlmdomain:DOMAIN",
System.Management.ImpersonationLevel.Impersonate,
System.Management.AuthenticationLevel.Default, true,
null, System.TimeSpan.MaxValue);
pw.Dispose();
ManagementScope scope =new ManagementScope("\\\\FullComputerName\\root\\cimv2", options);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"]);
}
}
}
|