Get ManagementObjectCollection : Management « Windows « C# / CSharp Tutorial






using System;
using System.Management;
public class RemoteConnect 
{
    public static void Main() 
    {
        ConnectionOptions options = new ConnectionOptions();
        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"]);
        }
    }
}








29.18.Management
29.18.1.Get ManagementObjectCollection
29.18.2.An EnumerationOptions variable with an EnumerationOptions constructor and then gets all the instances of a WMI class and its subclasses.
29.18.3.Connect to a remote computer and displays information about the operating system