<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Eduzine© - Win32</title>
    <link>http://eduzine.edujini-labs.com/</link>
    <description>Articles from Edujini Team</description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:" />
    <generator>Serendipity 0.8.2 - http://www.s9y.org/</generator>
    <pubDate>Tue, 06 May 2008 06:34:26 GMT</pubDate>

    <image>
        <url>http://www.edujini-labs.com/images/newmasthead.gif</url>
        <title>RSS: Eduzine© - Win32 - Articles from Edujini Team</title>
        <link>http://eduzine.edujini-labs.com/</link>
        <width></width>
        <height></height>
    </image>
<item>
    <title>Introduction to Windows Management Instrumentation</title>
    <link>http://eduzine.edujini-labs.com/archives/26-Introduction-to-Windows-Management-Instrumentation.html</link>
<category>Win32</category>    <comments>http://eduzine.edujini-labs.com/archives/26-Introduction-to-Windows-Management-Instrumentation.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=26</wfw:comment>
    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=26</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>


&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Web Based Enterprise Mangaement (WBEM) is an industry initiative that establishes management infrastructure standards
and provides a way to combine information from various hardware and software management systems. It specifies standards
for a unified architecture allowing access to data from multiple underlying technologies and platforms and presenting
it in a consistent fashion.
&lt;/p&gt;

 
&lt;p&gt;
Microsoft Windows Management Instrumentation (WMI) is WBEM-compliant. It provides a consistent and descriptive model
of the configuration, status and operational aspects of Microsoft Windows.
&lt;/p&gt;

&lt;p&gt;
In essence, WMI provides:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;Consitent model of Windows configuration, operation and status&lt;/li&gt;
	&lt;li&gt;A COM API providing a single point access to all management functions&lt;/li&gt;
	&lt;li&gt;Flexible architecture allowing vendors to extend the information model to cover new devices,
		applications, and other enhancements by writing WMI providers&lt;/li&gt;
	&lt;li&gt;WMI Query Language, WQL, that enables detailed queries of the information model&lt;/li&gt;
	&lt;li&gt;Scripting support, through Visual Basic, VBA, VBScript and JScript&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
In this article, we take the route of VBScript to discover some possibilities in WMI.
&lt;/p&gt;

&lt;h2&gt;What do we do?&lt;/h2&gt;

&lt;p&gt;
Let's create a simple VBScript to query WMI regarding the disks.
&lt;/p&gt;


&lt;h2&gt;Code and Analysis&lt;/h2&gt;

&lt;p&gt;
The first method that would ever used is to get the reference to the COM Object - winmgmts (CLSID: 172BDDF8-CEEA-11D1-8B05-00600806D9B6).
This is the &amp;quot;Wbem Scripting Object Path&amp;quot; / &amp;quot;Wbem Object Path 1.0&amp;quot; Component. The complete code is:
&lt;/p&gt;

&lt;pre&gt;GetObject(&amp;quot;winmgmts:\\{machine-name}\root\cimv2&amp;quot;)&lt;/pre&gt;

&lt;p&gt;
In the code above, {machine-name} refers to the machine where the query is to be performed subsequently. Should you wish to perform the
query on local machine, you can specify the name as &amp;quot;.&amp;quot; (dot).
&lt;/p&gt;

&lt;p&gt;
Now, I mentioned about WQL earlier. It's very similar to SQL, if you know that. To get started, it's identical. Let's query our machine
to some basic information.
&lt;/p&gt;

&lt;pre&gt; 1 Option Explicit&lt;br /&gt; 2 Dim objWMIService, objItem, colItems, strComputer&lt;br /&gt; 3&lt;br /&gt; 4 strComputer = &amp;quot;.&amp;quot;&lt;br /&gt; 5&lt;br /&gt; 6 Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt; 7 Set colItems = objWMIService.ExecQuery(&amp;quot;Select &lt;strong&gt; from Win32_ComputerSystem&amp;quot;)&lt;br /&gt; 8&lt;br /&gt; 9 For Each objItem in colItems&lt;br /&gt;10    Wscript.Echo &lt;u&gt;&lt;br /&gt;11        &amp;quot;Name: &amp;quot; &amp;amp; objItem.Name &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;12        &amp;quot;System Type: &amp;quot; &amp;amp; objItem.SystemType &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;13        &amp;quot;Manufacturer: &amp;quot; &amp;amp; objItem.Manufacturer &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;14        &amp;quot;Model: &amp;quot; &amp;amp; objItem.Model &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;15        &amp;quot;# Processors: &amp;quot; &amp;amp; objItem.NumberOfProcessors &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;16        &amp;quot;RAM: &amp;quot; &amp;amp; CInt(objItem.TotalPhysicalMemory / (1024 &lt;/strong&gt; 1024)) &amp;amp; &amp;quot; MB&amp;quot; &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;17        &amp;quot;Username: &amp;quot; &amp;amp; objItem.UserName &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;18        &amp;quot;Timezone: &amp;quot; &amp;amp; objItem.CurrentTimeZone &amp;amp; &amp;quot; mins from GMT&amp;quot; &amp;amp; vbCr&lt;br /&gt;19 Next&lt;br /&gt;20&lt;br /&gt;21 WSCript.Quit&lt;/pre&gt;

&lt;p&gt;
At line 6, we get a reference to the COM Object for the root CIM v2 for the machine. CIMv2 stands for Common Information Model Version 2.
&lt;br /&gt;
At line 7, we query the service for the class Win32_ComputerSystem.
&lt;br /&gt;
Subsequently, we iterate through all the items and extract the information. In this case, the loop iterates only once because
there is only one Computer System. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;br /&gt;
And the result is something as below:
&lt;/p&gt;

&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/WMI.001.Win32_ComputerSystem.jpg&quot; title=&quot;WMI Computer System Information&quot; alt=&quot;WMI Computer System Information&quot; /&gt;

&lt;p&gt;
Now, how about querying the information about the disk drive?
&lt;/p&gt;

&lt;pre&gt; 1 Option Explicit&lt;br /&gt; 2 Dim objWMIService, objItem, colItems, strComputer, intDrive&lt;br /&gt; 3&lt;br /&gt; 4 strComputer = &amp;quot;.&amp;quot;&lt;br /&gt; 5&lt;br /&gt; 6 Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt; 7 Set colItems = objWMIService.ExecQuery(&amp;quot;Select &lt;strong&gt; from Win32_DiskDrive&amp;quot;)&lt;br /&gt; 8&lt;br /&gt; 9 For Each objItem in colItems&lt;br /&gt;10    intDrive = intDrive + 1&lt;br /&gt;11    Wscript.Echo &lt;u&gt;&lt;br /&gt;12        &amp;quot;DiskDrive: &amp;quot; &amp;amp; intDrive &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;13        &amp;quot;Caption: &amp;quot; &amp;amp; objItem.Caption &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;14        &amp;quot;Description: &amp;quot; &amp;amp; objItem.Description &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;15        &amp;quot;Manufacturer: &amp;quot; &amp;amp; objItem.Manufacturer &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;16        &amp;quot;Model: &amp;quot; &amp;amp; objItem.Model &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;17        &amp;quot;Name: &amp;quot; &amp;amp; objItem.Name &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;18        &amp;quot;Partitions: &amp;quot; &amp;amp; objItem.Partitions &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;19        &amp;quot;Size: &amp;quot; &amp;amp; CInt(objItem.Size / (1024 &lt;/strong&gt; 1024 * 1024)) &amp;amp; &amp;quot; GB&amp;quot; &amp;amp; VbCr &amp;amp; _&lt;br /&gt;20        &amp;quot;SystemName: &amp;quot; &amp;amp; objItem.SystemName &amp;amp; VbCr&lt;br /&gt;21 Next&lt;br /&gt;22&lt;br /&gt;23 WSCript.Quit&lt;/pre&gt;

&lt;p&gt;
I don't think I need to explain the code above. Everything should be self-explanatory. The result is similar to the following:
&lt;/p&gt;

&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/WMI.002.Win32_DiskDrive.jpg&quot; title=&quot;WMI Computer System Information&quot; alt=&quot;WMI Computer System Information&quot; /&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
WMI provides a great way to manipulate all system information, including software and hardware.
What more - WMI Scripting provides a simple yet powerful mechanism for the same.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Mon, 05 May 2008 23:15:02 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/26-guid.html</guid>
    </item>
</channel>
</rss>
