 




<?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; UserAccounts.CommonDialog</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/useraccountscommondialog/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>
	</channel>
</rss>
