.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Getting Remote System Info Using WMI in C#

Posted By:Sunil Yadav       Posted Date: September 14, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

This article explains how we can connect to remote system using WMI query.

Following code demonstrates how we can connect to remote computer in c# using WMI queries. C# Code:

using System;
using System.Management;

namespace WMITest
    class GetSystemInfo
        static void Main(string[] args)


        static void GetTargetSystemInfo()
            ConnectionOptions oCon = new ConnectionOptions();
            Console.Write("Enter System Name or IP to be connected : ");
            string sTargetSystem = Console.ReadLine();
            Console.Write("Enter user name : ");

            oCon.Username = Console.ReadLine();
            Console.Write("Enter password : ");
            oCon.Password = Console.ReadLine();
            oCon.Authority = "ntlmdomain:DOMAIN";
            Console.WriteLine("Displaying system information for " + sTargetSystem + " ......");
            ManagementScope mgmtscope = new ManagementScope("\\\\" + sTargetSystem.Trim() + "\\root\\CIMV2", oCon);

            ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(mgmtscope, oQuery);

            ManagementObjectCollection queryCollection = searcher.Get();
            foreach (ManagementObject mgmtobj in queryCollection)
                // Display the remote computer information
                Console.WriteLine("System Name : {0}", mgmtobj.Properties["csname"].Value);
                Console.WriteLine("Operating System: {0}", mgmtobj.Properties["Caption"].Value);
                Console.WriteLine("OS Version: {0}", mgmtobj.Properties["Version"].Value);
                Console.WriteLine("Manufacturer : {0}", mgmtobj.Properties["Manufacturer"].Value);

            // Get system architecture (32-64 bit)
            oQuery.QueryString = "SELECT * FROM Win32_Processor";
            searcher.Query = oQuery;
            searcher.Scope = mgmtscope;
            queryCollection = searcher.Get();
            foreach (ManagementObject mgmtobj in queryCollection)
                Console.WriteLine("Bit : {0}", mgmtobj.Properties["AddressWidth"].Value.ToString());

            Console.WriteLine("Press any key to exit.");


That's it.
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend