<?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; vbscript tips</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/vbscript-tips/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>Using the windows file dialog box in VBScript to provide file selections and populate script options</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-windows-file-dialog-box-in-vbscript-to-provide-file-selections-and-populate-script-options/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-windows-file-dialog-box-in-vbscript-to-provide-file-selections-and-populate-script-options/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 16:36:29 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[File Dialog]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[UserAccounts.CommonDialog]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[vbscript tips]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-windows-file-dialog-box-in-vbscript-to-provide-file-selections-and-populate-script-options/</guid>
		<description><![CDATA[Sometimes the command line is great for getting a script running and doing the task a script was intended to do, however, sometimes you simply don&#8217;t want to add the overhead of opening a command prompt, navigating to the directory where your script is located, and then remembering the command line options you entered into [...]]]></description>
				<content:encoded><![CDATA[<p>Sometimes the command line is great for getting a script running and doing the task a script was intended to do, however, sometimes you simply don&#8217;t want to add the overhead of opening a command prompt, navigating to the directory where your script is located, and then remembering the command line options you entered into the script to make it run the last time. Then sometimes you just don&#8217;t want to hard code the file name into your script because you don&#8217;t want to have to change it every time.</p>
<p> In fact, sometimes your script is intended for users who might not even know how to run a script from the command line! Wouldn&#8217;t it be great if you could just have windows display a dialog box to prompt the user for a file to chose as a argument for your script?</p>
<p>Well, you CAN! The following script is a sample of what you can do with the Windows Common Dialog box to enable the user to more easily utilize your scripts&#8211; all without knowing about the command line!</p>
<p>There are a few key pieces of the script I want to call out before we dig in and start running the code though. First, the object that preforms the magic here is <font color="#000000"><em>UserAccounts.CommonDialog</em>, the filter options on the dialog in the drop down to select the file types to display in the browser dialog is the line with <em>.Filter</em> property in it, The initial Directory the dialog uses is specified in the .InitialDirectory Property, and finally the default selection of that drop down is specified in the .FilterIndex Property. Take a look at the code and see how easy it is.</font></p>
<p><font color="#0000ff"> Option Explicit<br />
Dim ObjFSO, InitFSO</font></p>
<p><font color="#0000ff">&#8216; create an instance of the File Browser<br />
Set ObjFSO = CreateObject(&#8220;UserAccounts.CommonDialog&#8221;)</font></p>
<p><font color="#0000ff">&#8216;setup the File Browser specifics<br />
ObjFSO.Filter = &#8220;VBScripts|*.vbs|Text Files|*.txt|All Files|*.*&#8221;<br />
ObjFSO.FilterIndex = 3<br />
ObjFSO.InitialDir = &#8220;c:\&#8221;</font></p>
<p><font color="#0000ff">&#8216; show the file browser and return the selection (or lack of) to InitFSO<br />
InitFSO = ObjFSO.ShowOpen</font></p>
<p><font color="#0000ff">If InitFSO = False Then<br />
    Wscript.Echo &#8220;Script Error: Please select a file!&#8221;<br />
    Wscript.Quit<br />
Else<br />
    WScript.Echo &#8220;You selected the file: &#8221; &amp; ObjFSO.FileName<br />
End If</font></p>
<p>Enjoy!</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-windows-file-dialog-box-in-vbscript-to-provide-file-selections-and-populate-script-options/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to use command line arguments in VBScript via the Wscript.Arguments Object</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-use-command-line-arguments-in-vbscript-via-the-wscriptarguments-object/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-use-command-line-arguments-in-vbscript-via-the-wscriptarguments-object/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 06:04:14 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[commandline]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[vbscript tips]]></category>
		<category><![CDATA[Wscript.Arguments]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-use-command-line-arguments-in-vbscript-via-the-wscriptarguments-object/</guid>
		<description><![CDATA[One thing that comes up frequently in my need to script tasks, is the ability to run a script from the command line, or as a scheduled job with parameters passed to it from the calling application. In a &#8220;set it and forget it&#8221; script it&#8217;s not such a big deal to have arguments passed [...]]]></description>
				<content:encoded><![CDATA[<p><font color="#000000">One thing that comes up frequently in my need to script tasks, is the ability to run a script from the command line, or as a scheduled job with parameters passed to it from the calling application. In a &#8220;set it and forget it&#8221; script it&#8217;s not such a big deal to have arguments passed to it, simply because you are likely to only use the script for one task&#8230; it will do it&#8217;s work and (hopefully) you never have to deal with it again. These are the best scripts! Ones where you save time every day when they run, and if they break you have to try to not only remember what they did, but where you scheduled them. </font></p>
<p><font color="#000000">The first time I wrote such a beast I changed the script several times until I had a couple copies doing the same task on different directories. I then tried to create a script that ran against all the directories, but that too became a pain when I wanted to run it as a one off or run it on a different schedule.</font></p>
<p> Then I figured out how to add command line arguments to my scripts! What a powerful and time saving piece of information that was to figure out!</p>
<p> Command line arguments in VBScript are really very simple, once you have the concepts down and know what object to use. Which, of course, is the Wscripts.Arguments object! With this object you can pass any number of arguments and parse them in your script or add them into a variable&#8211; or anything you want, the sky&#8217;s the limit!</p>
<p>Enough rambling on though, lets get to the code that will save you a ton of time!</p>
<p><font color="#0000ff">args = WScript.Arguments.Count</font></p>
<p><font color="#0000ff">If args &lt; 1 then<br />
  WScript.Echo &#8220;usage: args.vbs argument [argument] [argument] [argument] &#8221;<br />
  WScript.Quit<br />
end If</font></p>
<p><font color="#0000ff">WScript.Echo &#8220;You entered &#8221; &amp; args &amp; &#8221; Arguments, the first was &#8220;_<br />
 &amp; chr(34) &amp; WScript.Arguments.Item(0) &amp; Chr(34)<br />
</font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#000000">As always, this code works perfectly. However, sometimes the formatting of the blog breaks the code if you copy and paste it into your editor. So, if you’d like to not type or troubleshoot any syntax errors due to the copy and paste problems&#8211; I’ve provided the code for download, plus example output files  from my final tests for you. You’ll find the code and other files available for download from my website’s (<a href="http://www.websystemsadministration.com/">www.websystemsadministration.com</a>) File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.<font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></font></font></p>
<p></font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-use-command-line-arguments-in-vbscript-via-the-wscriptarguments-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Top 10 concepts to grasp in order to write useful scripts in VBScript (Part 2)</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-2/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-2/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 22:40:19 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[advice]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[vbscript tips]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-2/</guid>
		<description><![CDATA[In my last posting I gave you 5 of what I consider to be 5 of the top 10 things to grasp so that you can be successful in writing powerful VBScripts to make your life easier. In this installment I finish up these trains of thought. So lets dive back in: 5. Always try [...]]]></description>
				<content:encoded><![CDATA[<p>In <a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-1/">my last posting</a> I gave you 5 of what I consider to be 5 of the top 10 things to grasp so that you can be successful in writing powerful VBScripts to make your life easier. In this installment I finish up these trains of thought. So lets dive back in:</p>
<p><strong>5. Always try to use option explicit in your code, especially if the script is longer than 100 lines.</strong></p>
<p>Trust me on this one, using option explicit may force you to think a little bit about declaring a variable before you use it and it may be a pain having a silly error about a undeclared variable when you test your code, but it&#8217;s a heck of a lot better than trying to find two places where you&#8217;ve spelled a variable two different ways in your code&#8211; and creating a hard to find bug because of the different spellings.</p>
<p><strong>4. Learn when to use on error resume next and when to just let the script die.</strong></p>
<p>Sometimes you just can&#8217;t cover all the possible errors in your code (though you should try) and turning off error checking is an absolute must. When you do do this, be sure and turn error checking back on after you have passed over the area of your code that could cause a problem (with&#8211; <em>on error goto 0</em>)</p>
<p><strong>3.  Conditional statements are invaluable, just know what tool is right for the job.</strong></p>
<p>Branching your script because a variable has a specific value, is greater than, or less than something else can be invaluable. Often it is the key to clearer to follow code and getting your script up and running quickly. Knowing which conditional statement (If-then-else, for-next, do-loop,  select-case, etc) to use is an invaluable tool to have in your tool belt as a systems administrator.</p>
<p><strong>2. If you do it over and over, then you should script it.</strong></p>
<p>This is my motto! You&#8217;ve seen it several times&#8230; <strong>BE LAZY!</strong> There is absolutely no sense in doing something that is repeatable by hand day in and day out. Your time could be better spent spending a few seconds looking at a output from a script to make sure it went well when it ran as a scheduled task. Thus freeing you up to do more (or less) of what you need to accomplish during the day.</p>
<p><strong>1. Everything has been done before, it just may take a little effort on your part to cobble it together.</strong></p>
<p>Almost everything has been done before in a script or other program&#8230; it just may not be exactly what you need to get the job done. After searching for a while for a script that does exactly what you want and not finding it&#8212; look for several scripts that do pieces of what you need done and put them together into one script that is exactly what you need! Above all else use Google for what it does best, search the web for examples. Additionally, as you find sites that are helpful book mark them for later reference. My blog roll to the right is a good place to start as well, I use these sites myself.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 concepts to grasp in order to write useful scripts in VBScript (Part 1)</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-1/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-1/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 06:02:56 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[advice]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[vbscript tips]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-1/</guid>
		<description><![CDATA[In this installment I thought I&#8217;d give the network administrator looking to learn VBScript a little help in focusing in of key skills needed to write not only useful VBScripts, but help them make their lives easier! There are certainly more concepts that are helpful, but these are the ones I think are the most basic [...]]]></description>
				<content:encoded><![CDATA[<p>In this installment I thought I&#8217;d give the network administrator looking to learn VBScript a little help in focusing in of key skills needed to write not only useful VBScripts, but help them make their lives easier! There are certainly more concepts that are helpful, but these are the ones I think are the most basic to everything else.</p>
<p>So let&#8217;s dive in with Number 10!</p>
<p><strong>10.</strong> <strong>String Manipulation is your friend.</strong></p>
<p>There&#8217;s a reason people are still writing scripts in PERL. It is very useful in manipulating strings&#8211; and sometimes you need to manipulate and use strings to get done what you need to get done. Built in String manipulation functions like Replace(), Instr(), Mid(), Ucase(), and Lcase() are invaluable, so commit their syntax to memory or use a script editor with intellisense that will help you with the syntax as you type.</p>
<p><strong>9. Learning to create functions and subroutines will make your life easier.</strong></p>
<p>The key to generating a script quickly is to use the code you&#8217;ve already worked hard on creating previously. Most of my scripts that I post here are smaller for a single purpose but, they are still useful if you take the heart of the script and wrap it in a function! You will find, over time, you&#8217;ll end up digging through your script repository to copy and paste pieces of code into another script. (I do.) Plus, it will save you time! Be Lazy! Don&#8217;t re-invent the wheel every time you sit down in front of the keyboard! </p>
<p><strong>8. Key scripting objects were created for a reason&#8211; so you don&#8217;t have to create them yourself.</strong></p>
<p>This is a continuation of the same concept. Don&#8217;t re-invent the wheel. There are already objects for specific functions, string manipulation for example&#8211; so don&#8217;t reinvent the replace() statement unless you have a really good reason to do so. If you need a little different functionality try to at least wrap it in a function.</p>
<p><strong>7. Recursion in your code can be your best friend&#8211; or your worst enemy.</strong></p>
<p>Recursion is where a section of code (generally a function) calls itself. This is invaluable! It saves a ton of lines of code because sometimes you do need to use the functionality of a function inside itself. (file and directory manipulations for example) However, be aware that recursion is dangerous because it poses the potential to create an infinite loop (which would be very bad if you were deleting files) and also can be somewhat hard to troubleshoot.</p>
<p><strong>6. You will eventually need to debug that script, so comment your code and use Wscript.Echo to write to the screen what you are doing.</strong></p>
<p>It&#8217;s inevitable, at some point a situation is going to arise that you didn&#8217;t think of 3 years ago when you wrote the script and your going to have to figure out why that script you wrote (and forgot about) has been dying for 6 months.</p>
<p>Comments are helpful in documenting how and why a script is doing something in a particular manner. I can&#8217;t tell you how many times I&#8217;ve went to the effort to rewrite a section of code to find out my thought wasn&#8217;t going to work because of something I figured out previously and didn&#8217;t document or didn&#8217;t because the code didn&#8217;t make sense.</p>
<p>Another useful tip is to use Wscript.Echo to output the key information the script is using, a variable in a <strong>For Next</strong> loop for example, or a string being passed into a function and the output of the function. You can always either comment them out when you&#8217;re done &#8212; or use a variable to hold a &#8220;debug state&#8221; and wrap the Wscript.Echo in a if statement, like so:</p>
<p><font color="#0000ff">&#8216;This is the debug &#8220;flag&#8221;, set it to 0 to turn off debugging output<br />
</font><font color="#0000ff">Debug =1</font></p>
<p><font color="#0000ff">&#8216;&#8230; lots of code omitted</font></p>
<p><font color="#0000ff">If debug = 1 then<br />
     Wscript.Echo &#8220;We&#8217;re cooking with Gas now!&#8221;<br />
End if</font></p>
<p><font color="#000000">That&#8217;s enough for now, you&#8217;ll at least have something to consider. There&#8217;s more in the next Blog posting, so <a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-2/">continue on over there</a>!</font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/top-10-concepts-to-grasp-in-order-to-write-useful-scripts-in-vbscript-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
