SIGN UP MEMBER LOGIN:    
ARTICLE

Interrogating Systems with WMI

Posted by John O Donnell Articles | Networking January 18, 2002
WMI allows you to retrieve information such as hardware types, software installed and much much more.
Reader Level:

Ever wondered how to create a Winmsd type program to interrogate yours or other systems on the network?

Microsoft has the answer with a technology called WMI or Windows Management Instrumentation.

(WMI is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment.

WMI allows you to retrieve information such as hardware types, software installed and much much more. This is powerful enough on a local system but WMI allows you to interrogate other systems over a network connection. WMI allows you to create an enterprise application to track the status of all your computers on the network.

All the information is provided by the WinMgmt.exe service. When you use this code you are running queries through this service.

Here is the code for Beta2 of .net although it will work on most versions.

//WMI.cs
//Extracts computer system information using WMI from Microsoft
//Written 01/17/02 John O'Donnell - csharpconsulting@hotmail.com
using System;
using System.Management;
namespace WMI
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
Console.WriteLine("Written 01/17/02 By John O'Donnell - csharpconsulting@hotmail.com");
Console.WriteLine("========================================================================="); ManagementObjectSearcher query1 =
new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") ;
ManagementObjectCollection queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
Console.WriteLine("Name : " + mo["name"].ToString());
Console.WriteLine("Version : " + mo["version"].ToString());
Console.WriteLine("Manufacturer : " + mo["Manufacturer"].ToString());
Console.WriteLine("Computer Name : " +mo["csname"].ToString());
Console.WriteLine("Windows Directory : " + mo["WindowsDirectory"].ToString());
}
query1 =
new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") ;
queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
Console.WriteLine("Manufacturer : " + mo["manufacturer"].ToString());
Console.WriteLine("Model : " + mo["model"].ToString());
Console.WriteLine(mo["systemtype"].ToString());
Console.WriteLine("Total Physical Memory : " + mo["totalphysicalmemory"].ToString());
}
query1 =
new ManagementObjectSearcher("SELECT * FROM Win32_processor") ;
queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
Console.WriteLine(mo["caption"].ToString());
}
query1 =
new ManagementObjectSearcher("SELECT * FROM Win32_bios") ;
queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
Console.WriteLine(mo["version"].ToString());
}
query1 =
new ManagementObjectSearcher("SELECT * FROM Win32_timezone") ;
queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
Console.WriteLine(mo["caption"].ToString());
}
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor