<?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>Ed&#039;s Place &#187; Scripting</title>
	<atom:link href="http://www.edfrancis.co.uk/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.edfrancis.co.uk</link>
	<description>The home of Ed&#039;s Rants and Raves since 2008!</description>
	<lastBuildDate>Tue, 13 Jul 2010 16:33:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Back up Network Connected Printers via a VBScript</title>
		<link>http://www.edfrancis.co.uk/2010/02/back-up-network-connected-printers-via-a-vbscrip/</link>
		<comments>http://www.edfrancis.co.uk/2010/02/back-up-network-connected-printers-via-a-vbscrip/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 20:30:09 +0000</pubDate>
		<dc:creator>Ed Francis</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.edfrancis.co.uk/?p=552</guid>
		<description><![CDATA[The following script can be used to back up all network printers connected to Windows. Its been tested on Windows XP (SP2 and SP3) and Windows 7. The script simply outputs to the command window the syntax for a restoration script. Running this script from the command line, you&#8217;ll be able to control where this [...]]]></description>
			<content:encoded><![CDATA[<p>The following script can be used to back up all network printers connected to Windows. Its been tested on Windows XP (SP2 and SP3) and Windows 7.</p>
<p>The script simply outputs to the command window the syntax for a restoration script. Running this script from the command line, you&#8217;ll be able to control where this output goes rather than just being stuck with wherever I guess you want it.</p>
<p>Simply paste the following code to a vbs file of your choice then run it using the following command:<br />
cscript &lt;<em>scriptname</em>&gt;.vbs //nologo &gt; &lt;<em>target-filename</em>&gt;.vbs</p>
<p>Its a bit of a fiddle but it does mean this script is fire and forget. You&#8217;ll never need to change it if you server changes its name etc.</p>
<pre>'Script to automatically generate a printer recreation script.
'The output of this script should be piped out to a .vbs file
'using the //nologo switch</pre>
<p><code> </code></p>
<pre>Dim strDefaultPrinter</pre>
<p><code> </code></p>
<pre>Wscript.Echo "'Automatically generated script to restore printers"
Wscript.Echo "'This script should be executed to recreate network printers only"
Wscript.Echo ""
Wscript.Echo "Set objNetwork = CreateObject(""WScript.Network"")"</pre>
<p><code> </code></p>
<pre><span style="font-family: monospace; line-height: 19px; white-space: normal; font-size: 13px;">s</span>trComputer = "."
strDefaultPrinter = "NotSet"</pre>
<p><code> </code></p>
<pre><span style="font-family: monospace; line-height: 19px; white-space: normal; font-size: 13px;">S</span>et objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")</pre>
<p><code> </code></p>
<pre>For Each objPrinter in colPrinters
  If objPrinter.Attributes And 64 Then
    Wscript.Echo "' ** Local printer included for information only: " &amp; objPrinter.Name
  Else
    strPrinterType = "objNetwork.AddWindowsPrinterConnection "
    Wscript.Echo strPrinterType &amp; """" &amp; objPrinter.Name &amp; """"
    If objprinter.Default = True then
      StrDefaultPrinter = objPrinter.Name
    End If
  End If
Next</pre>
<p><code> </code></p>
<pre><span style="font-family: monospace; line-height: 19px; white-space: normal; font-size: 13px;">I</span>f StrDefaultPrinter &lt;&gt; "NotSet" then
  Wscript.Echo ""
  Wscript.Echo "objNetwork.SetDefaultPrinter " &amp; """" &amp; StrDefaultPrinter &amp; """"
End If</pre>
<p><code> </code></p>
<p>Well, that&#8217;s a bit of a mouthful. Let&#8217;s break this script down so we know what&#8217;s going on.</p>
<p>The first portion of the script (I&#8217;m ignoring the preamble comment lines) is all about setting up variable and strDefaultPrinter which will be used later to set a default printer if its needed. We also make sure the script&#8217;s pointing at the current PC.<br />
Next, we call the GetObject function to climb into the guts of Windows and set ourselves up for asking it a question.<br />
The next line simply asks for a list of all installed printers.</p>
<p>The rest of the script steps through the list (For Each&#8230;. Next) and runs a couple of &#8220;If&#8221; statements to work out if the printer&#8217;s local (add a comment line) or networked (add a line to recreate the printer) then finally if it is a network printer, is it the default one.</p>
<p>When we&#8217;ve finished the loop, we drop out to a final If statement, this simply checks if the default printer was set by one of the network printers triggering the change. If not, it does nothing, if there is a default printer set, it adds the line.</p>
<p>Well, that&#8217;s it for now. Please slap a comment on the post if there&#8217;s any part you&#8217;d like walking through. As usual, this script represents a collection from  a number of sources being skimmed for various lines of code.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.edfrancis.co.uk/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.edfrancis.co.uk/2010/02/back-up-network-connected-printers-via-a-vbscrip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Explorer Command Line</title>
		<link>http://www.edfrancis.co.uk/2008/08/125/</link>
		<comments>http://www.edfrancis.co.uk/2008/08/125/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 12:00:08 +0000</pubDate>
		<dc:creator>Ed Francis</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://blog.mrfrancis.net/?p=125</guid>
		<description><![CDATA[Just because I&#8217;m that sad, I thought you might like a couple of handy ways to launch explorer so its where you want rather than drilling down to places. Many people know the &#8220;Explorer X:\&#8221; trick that takes you to whatever you have as your X drive but have you noticed it doesn&#8217;t have the folders [...]]]></description>
			<content:encoded><![CDATA[<p>Just because I&#8217;m that sad, I thought you might like a couple of handy ways to launch explorer so its where you want rather than drilling down to places.<br />
Many people know the &#8220;Explorer X:\&#8221; trick that takes you to whatever you have as your X drive but have you noticed it doesn&#8217;t have the folders listed in the left hand pane? Useless!</p>
<p>Here&#8217;s a few that you might not know. Let&#8217;s start with solving the problem above:</p>
<p>Explorer /e, X:\<br />
That&#8217;s open explorer, with the default view (i.e. showing folders) to the X drive</p>
<p>Explorer /e, X:\Work in Progress<br />
Open my X drive, open the Work in Progress directory, showing folders in the left hand pane (interestingly, there&#8217;s no need for speech marks even though the path contains spaces)</p>
<p>You can do:<br />
Explorer /root, \\server_name\share<br />
To open that file share, however you could just type in the path to the run box instead and it should open correctly anyhow!!</p>
<p>There you go, sad but may come in handy one day (when making shortcuts for users or whatever). You never know.</p>
<p><strong>Update:</strong> For more, have a look at <a href="http://support.microsoft.com/kb/130510" target="_blank">Microsoft&#8217;s Site</a> where it details additional things like opening Explorer with a particular file highlighted and stuff. Genius!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.edfrancis.co.uk/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.edfrancis.co.uk/2008/08/125/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just Hold on a Minute There! &#8211; Making a Batch File Wait</title>
		<link>http://www.edfrancis.co.uk/2008/06/just-hold-on-a-minute-there-making-a-batch-file-wait/</link>
		<comments>http://www.edfrancis.co.uk/2008/06/just-hold-on-a-minute-there-making-a-batch-file-wait/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 16:53:26 +0000</pubDate>
		<dc:creator>Ed Francis</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://blog.mrfrancis.net/?p=33</guid>
		<description><![CDATA[I read a fascinating web page today while I was trying to get a batch file I was writing to wait a few seconds before executing its next command. Running off to the net I managed to find the information on Rob van de Woude&#8217;s website at http://www.robvanderwoude.com/wait.php. The way he tackles the problem is to ping [...]]]></description>
			<content:encoded><![CDATA[<p>I read a fascinating web page today while I was trying to get a batch file I was writing to wait a few seconds before executing its next command. Running off to the net I managed to find the information on Rob van de Woude&#8217;s website at <a href="http://www.robvanderwoude.com/wait.php" target="_blank">http://www.robvanderwoude.com/wait.php</a>.</p>
<p>The way he tackles the problem is to ping an unknown ip address (thus causing an error) and setting that ping to wait a set amount of time before trying again. Having told the command to only attempt the ping once, it will then pass control back to the batch file. Adding insult to injury, even the error message is elegantly sent to &#8220;&gt;nul&#8221; or <em>nowhere</em> if you like. Brilliant!</p>
<p>I know, I know. Its geeky but just try to remember, this is me writing this! <img src='http://www.edfrancis.co.uk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.edfrancis.co.uk/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.edfrancis.co.uk/2008/06/just-hold-on-a-minute-there-making-a-batch-file-wait/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing Folder Contents to a Text File</title>
		<link>http://www.edfrancis.co.uk/2008/05/listing-folder-contents-to-a-text-file/</link>
		<comments>http://www.edfrancis.co.uk/2008/05/listing-folder-contents-to-a-text-file/#comments</comments>
		<pubDate>Sat, 03 May 2008 15:04:59 +0000</pubDate>
		<dc:creator>Ed Francis</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://blog.mrfrancis.net/?p=18</guid>
		<description><![CDATA[My brother in law Matt (take a bow buddy!) asked me a good one the other day. He had a directory (I still call them that, I know, they’re called Folders now) which contained a number of files that he wanted to be able to print a list of. No, I don’t know why he [...]]]></description>
			<content:encoded><![CDATA[<p>My brother in law Matt (take a bow buddy!) asked me a good one the other day. He had a directory (I still call them that, I know, they’re called Folders now) which contained a number of files that he wanted to be able to print a list of.<br />
No, I don’t know why he wanted it either but it’s a good theoretical example that can show off how easy this kind of stuff can be from my homeland, the command line.</p>
<p>Once more, unto the DOS dear friends….<br />
In order to get a list of files whenever we find ourselves on the rocky shores of the command line (you know, the place you go if you type <em>cmd</em> in the run box) you use the very handy and occasionally powerful dir command.<br />
Dir does what it says on the tin, it gives you a directory list of the files in that directory. Where it gets powerful is when you combine it with the switches it can use. A switch is a special parameter you pass to the command to tell it how to behave. With most commands you can get a list of their switches and their uses by following the command with the /? switch (Eg <em>dir /?</em>).</p>
<p>Lets just go straight for the example I gave Matt. The commands will take you to a directory on the C drive of the PC you’re on (in this case we want the contents of the C:\Music directory) then list the contents of that directory into a text file for you.<br />
<em>C:<br />
Cd\<br />
Cd Music<br />
Dir /b &gt;C:\EdsExampleFile.txt</em></p>
<p>This is readable and doesn’t come with all the details of the files (making it a handy list for other purposes). It does however list any child directory names too. To get it even more useful, we can use more switches in the Dir command line to make it hide those folder names.<br />
The /a switch is used to list files that have a particular attribute set (that it’s a directory, a hidden file, read-only, that sort of stuff). To list all directories you’d type dir /ad. Here we don’t want them so the command line should now be:<br />
<em>Dir /b /a-d &gt;C:\EdsExampleFile.txt</em></p>
<p>Oh, and if we just wanted a list of the .mp3 files in that folder (see, what I did there? Using the right term) you’d go:<br />
<em>Dir /b *.mp3</em></p>
<p>Easy peasy!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.edfrancis.co.uk/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.edfrancis.co.uk/2008/05/listing-folder-contents-to-a-text-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting your PC to shut down automatically at a set time of day</title>
		<link>http://www.edfrancis.co.uk/2008/05/setting-your-pc-to-shut-down-automatically-at-a-set-time-of-day/</link>
		<comments>http://www.edfrancis.co.uk/2008/05/setting-your-pc-to-shut-down-automatically-at-a-set-time-of-day/#comments</comments>
		<pubDate>Fri, 02 May 2008 12:38:58 +0000</pubDate>
		<dc:creator>Ed Francis</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://blog.mrfrancis.net/?p=17</guid>
		<description><![CDATA[I&#8217;ve been asked before how to set up a PC to automatically shut itself down at a particular time. In circumstances where there are a large number of PCs, this becomes one of the only options that are workable if you have a number of users who refuse to shut down their PCs. In Windows [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked before how to set up a PC to automatically shut itself down at a particular time. In circumstances where there are a large number of PCs, this becomes one of the only options that are workable if you have a number of users who refuse to shut down their PCs.</p>
<p>In Windows XP, this is an easy task to manage.</p>
<p>In days gone by, you could use the command AT to set up scheduled tasks to run. This was OK and did the job adequately but it didn&#8217;t give you complete control of the task that would be created. For example, by using AT, you would create the task name AT1. That&#8217;s what it would be called; don&#8217;t like it? Tough!</p>
<p>Now, in Windows XP the command SCHTASKS has joined the party. In order to show you how to use it, let&#8217;s answer the original question.</p>
<p>Q- How do I set my PC to shut down every day at the same time?<br />
A- Run the following command at the command line (Start &#8211; Run &#8220;cmd&#8221;):</p>
<p>SCHTASKS /Create /TN &#8220;Shutdown PC at Night&#8221; /TR &#8220;C:\Windows\System32\Shutdown.exe /s /f&#8221; /RU domain\username /RP password /SC DAILY /ST 21:30:00</p>
<p>OK, scary isn&#8217;t it? Let&#8217;s break it down:<br />
SCHTASKS /Create (Create a task)<br />
/TN &#8220;Task name&#8221; (Call the task by this name)<br />
/TR &#8220;command line&#8221; (Run this command)<br />
/RU domain/username (Run as this user)*<br />
/RP password (with this password)<br />
/SC DAILY (Schedule to run daily)<br />
/ST 21:30:00 (Run at 21:30)</p>
<p>* the /RU command can also be used thus: /RU computername/username</p>
<p>In order to get a better idea of the kind of power this command can have, simply run SCHTASKS /CREATE /? at the command line. It&#8217;ll tell you what you want to know.</p>
<p>This was a very brief description of one of the many functions available through SCHTASKS.exe and Shutdown.exe, I&#8217;ll get into some others on further posts regarding these brilliant (and free) utilities.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.edfrancis.co.uk/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.edfrancis.co.uk/2008/05/setting-your-pc-to-shut-down-automatically-at-a-set-time-of-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
