Affichage des articles dont le libellé est Scripting. Afficher tous les articles
Affichage des articles dont le libellé est Scripting. Afficher tous les articles

mercredi, février 01, 2006

WMI Example : My computer SOME hardware's informations

this is a simple example using the WMI features, to execute it you need to add to your form an listView named "listViewResult", also the reference to System.management

using System.Management;

ManagementObjectSearcher query;
ManagementObjectCollection queryCollection;
System.Management.ObjectQuery oq;

ConnectionOptions co = new ConnectionOptions();
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\localhost\\root\\cimv2", co);

oq = new System.Management.ObjectQuery("SELECT * FROM Win32_ComputerSystem ");
query = new ManagementObjectSearcher(ms, oq);

queryCollection = query.Get();

this.listViewResult.BeginUpdate();
this.listViewResult.Clear();

foreach (ManagementObject queryData in queryCollection)
{
foreach (PropertyData queryDataRow in queryData.Properties)
{
try
{
ListViewItem listItem = new ListViewItem(queryDataRow.Name.ToString());
listItem.SubItems.Add(queryDataRow.Value.ToString());
this.listViewResult.Items.Add(listItem);
}
catch
{
continue;
}
}
}

this.listViewResult.Columns.Add("Name", 200, HorizontalAlignment.Left);
this.listViewResult.Columns.Add("Value", 200, HorizontalAlignment.Left);
this.listViewResult.EndUpdate();

Here is the result :


WMI : Windows management instrumentation (Intro)

The purpose of WMI is to provide a uniform interface for any local or remote applications or scripts that obtain management data from a computer system, network, or enterprise. The uniform interface WMI layer means that applications and scripts which are clients to WMI do not have to call a wide variety of operating system application programming interfaces (APIs), many of which cannot be called by automation clients like scripts or Visual Basic applications. Many operating system APIs also do not make calls to remote machines.
A management application communicates with WMI through a variety of languages, such as Visual Basic, C++, ODBC, and ActiveX. All scripting languages that can handle ActiveX objects can access WMI data. All WMI interfaces are based on the Component Object Model (COM). After WMI retrieves data, it stores the data using the Common Information Model, a public standard.