 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator&#039;s Cafe &#187; Objects</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/objects/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>VBScript Statements: Explanation of the Set Statement</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explanation-of-the-set-statement/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explanation-of-the-set-statement/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 22:00:48 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Objects]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[set command]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[VBScript Objects]]></category>
		<category><![CDATA[VBScript Statements]]></category>
		<category><![CDATA[working with objects]]></category>
		<category><![CDATA[working with variables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explanation-of-the-set-statement/</guid>
		<description><![CDATA[The set statement is used to assign any value to any type of variable. For the most part this command is optional. However, it needs to be used when you are assigning an object reference to a variable, such as when you use a variable to hold the return of a CreateObject function for later reference [...]]]></description>
				<content:encoded><![CDATA[<p>The set statement is used to assign any value to any type of variable. For the most part this command is optional. However, it needs to be used when you are assigning an object reference to a variable, such as when you use a variable to hold the return of a CreateObject function for later reference in your code.</p>
<p>An example of the set command would look like:</p>
<p><font color="#0000ff">Option explicit<br />
Dim objDictionary<br />
Set objDictionary = CreateObject(”Scripting.Dictionary”)</font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explanation-of-the-set-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Set, GetObject, ExecQuery, and For Next in VBSCRIPT to use WMI objects</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-set-getobject-execquery-and-for-next-in-vbscript-to-use-wmi-objects/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-set-getobject-execquery-and-for-next-in-vbscript-to-use-wmi-objects/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 21:11:40 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Objects]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[VBScript Statements]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-set-getobject-execquery-and-for-next-in-vbscript-to-use-wmi-objects/</guid>
		<description><![CDATA[In my last blog entry I explained error control via on error resume next and on error goto 0, there are other ways as well&#8211; but for now this should work to get us by. Next well discuss the Set, GetObject, ExecQuery, and &#8220;For Each&#8221; commands in the script we worked with, these are on lines 3, [...]]]></description>
				<content:encoded><![CDATA[<p>In my last blog entry I explained error control via <strong><em>on error resume next</em></strong> and <strong><em>on error goto 0</em></strong>, there are other ways as well&#8211; but for now this should work to get us by.</p>
<p>Next well discuss the <strong>Set, </strong><strong>GetObject, ExecQuery, and &#8220;For Each&#8221;</strong> commands in the script we worked with, these are on lines 3, 4 and 5 below.</p>
<p><font face="Times New Roman">The script was basically (line numbers included as a reference):</font></p>
<p class="MsoNormal"><font face="Times New Roman">1. On Error Resume Next<br />
2.  </font><font face="Times New Roman">strComputer = “.”<br />
</font><font face="Times New Roman">3. Set objWMIService = GetObject(”winmgmts:\\” &amp; strComputer &amp; “\root\cimv2″)<br />
4. </font><font face="Times New Roman">Set colItems = objWMIService.ExecQuery(”Select * from </font><font face="Times New Roman">Win32_PrinterDriver”,,48)<br />
5. </font><font face="Times New Roman">For Each objItem in colItems<br />
6. </font><font face="Times New Roman">    Wscript.Echo “ConfigFile: ” &amp; objItem.ConfigFile<br />
7. </font><font face="Times New Roman">    Wscript.Echo “DataFile: ” &amp; objItem.DataFile<br />
8. </font><font face="Times New Roman">    Wscript.Echo “DriverPath: ” &amp; objItem.DriverPath<br />
9.</font><font face="Times New Roman">     Wscript.Echo “Name: ” &amp; objItem.Name<br />
10.</font><font face="Times New Roman">   Wscript.Echo “OEMUrl: ” &amp; objItem.OEMUrl<br />
11.</font><font face="Times New Roman">   WScript.Echo “_________________” &amp; vbcrlf<br />
12. </font><font face="Times New Roman">Next</font></p>
<p><font face="Times New Roman">The <em><strong>Set</strong></em> command basically tells cscript (or wscript) to assign the value of a variable to be the value of another or creates an <em>object</em>. For all intensive purposed, you can think of an object as a piece of specialized code that is already written that you can call from within your program and use as if it were your own. An object can contain many different types of values, that are referenced by names. These names are either properties (values) or methods (functions to do something and probably give you a value back).</font></p>
<p><font face="Times New Roman">Next, the GetObject command. this is the true heart of our WMI script. In fact, this is where almost all the magic happens! The Getobject comamnd lets us use pieces of code outside of our application as if we had written them on our own&#8211; the plus being that we don&#8217;t have to write them. In this case it is a WMI call to retrieve an object called &#8220;<em>winmgmts:\\.\root\cimv2&#8243;.</em></font></p>
<p><font face="Times New Roman">This object is the root WMI provider that is built into the OS and the period represents the local machine, to get other machine you would specify it&#8217;s name instead&#8211; this is why we used a variable in the script. (Remember, scripts are powerful when they are reusable for the same situation at a different time, so try to use variables where ever you think a piece of information could change in the furture to allow you to reuse the script.) This WMI provider returns a WMI object that allows us to reference and use the piece of the OS that deals with WMI. Notice we <strong>SET</strong> the object to the variable <em>objWMIService</em> in the line?</font></p>
<p><font face="Times New Roman"> In the next line of code we actually USE it, again another <strong>SET</strong> command. But this time we use:<br />
</font><font face="Times New Roman"><em>&#8230; objWMIService.ExecQuery(”Select * from <font face="Times New Roman">Win32_PrinterDriver”&#8230;.</font></em></font></p>
<p><font face="Times New Roman">The <em>execQuery</em> method is a part of the WMI classes Microsoft has written, and we are simply calling it to preform work. In this case, we are constructing a call to pull back all the printer drivers. The part in the quotes works exactly like a simple SQL statement would operate. Essentially in english it works like&#8211; <em>Select </em><strong>all values</strong><em> from </em><strong>Table containing the printer driver information. </strong>This &#8220;table&#8221; contains lots of information on the printer drivers, I&#8217;ve only chosen to show a few items from the table, you can get more information <a href="http://msdn2.microsoft.com/en-us/library/aa394366(VS.85).aspx">here</a>.</font></p>
<p><font face="Times New Roman">After this command completes, <em>colItems</em> will contain a collection of objects that each have properties named the same as the columns in the table. We use the <strong>For Each </strong>command on line 5 to loop through each member of a collection one at a time and do something with the data (or to the data). The <strong>Next</strong> command on line 12 loops back to the b<span>eginning</span> as long as there is another object after the one currently being used in the collection.</font></p>
<p><font face="Times New Roman">That&#8217;s it! It&#8217;s pretty easy stuff, once you get the concepts down. Remember, The WMI object is used to execute a query against the WMI database on the system. This query returns a collection of objects containing data for the query you built.</font></p>
<p><font face="Times New Roman">The actual data returned (and names of methods and properties used to get the data) depends on the query you specified. More on that next time!</font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-set-getobject-execquery-and-for-next-in-vbscript-to-use-wmi-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
