<?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>Remote Administration For Windows &#187; Scripts</title>
	<atom:link href="http://www.intelliadmin.com/index.php/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelliadmin.com</link>
	<description>Windows Network Administration Software</description>
	<lastBuildDate>Wed, 08 Feb 2012 13:36:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Force install of security patches &#8211; Across your network</title>
		<link>http://www.intelliadmin.com/index.php/2012/01/force-install-of-security-patches-across-your-network/</link>
		<comments>http://www.intelliadmin.com/index.php/2012/01/force-install-of-security-patches-across-your-network/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 05:12:42 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Network Administrator]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4673</guid>
		<description><![CDATA[I got a question from Mike this week: &#8220;Hi steve. Hope all is well. I am the IT manager at a small bank in Texas. We have lots of patch management tools&#8230;so I am not looking for that. Before an audit I would like to quickly force all of my machines to download and install [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2012/01/force-install-of-security-patches-across-your-network/" title="Permanent link to Force install of security patches &#8211; Across your network"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/AutomaticUpdate.jpg" width="55" height="68" alt="Post image for Force install of security patches &#8211; Across your network" /></a>
</p><p>I got a question from Mike this week:</p>
<p><em>&#8220;Hi steve. Hope all is well. I am the IT manager at a small bank in Texas. We have lots of patch management tools&#8230;so I am not looking for that. Before an audit I would like to quickly force all of my machines to download and install the latest security patches from MS. Is there any way to force Windows to do this from the command line? And I mean like right now! <img src='http://www.intelliadmin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Not next Tuesday. Thanks!&#8221;</em></p>
<p>I came across a script right on Microsoft&#8217;s website that can do something close to what you want:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx</a></p>
<p>It has a few issues. First, it tries to install all patches. Like the latest version of Internet Explorer, major service packs, and that ridiculous Windows Search 4.0. These require user intervention, and might even break things.</p>
<p>Another issue with the script is that it does not let you know when it failed because the network is down.</p>
<p>We took that script changed it to only include security updates. That way it gets to the core of the issue &#8211; getting the latest security patches, without any extra stuff.</p>
<p>With our new version of the script we created a plugin for <a href="http://www.intelliadmin.com/index.php/network-administrator/">Network Administrator</a>. This will allow you to remotely install the latest security patches across your network:</p>
<p><img src="http://www.intelliadmin.com/images2/Network%20Administrator%20Downloading%20Updates.jpg" alt="Force Automatic Update Across your Network"/></p>
<p>If the computer already is up to date, it will say: &#8220;This computer is up to date&#8221;</p>
<p>You can tell it to just download, or download and install. There is even an option to reboot when the install is complete:</p>
<p><img src="http://www.intelliadmin.com/images2/Force%20Security%20Patch%20Settings.jpg"></p>
<p>The free version allows you to work with three computers at a time. You can get it from our download page:</p>
<p><a href="http://www.intelliadmin.com/index.php/downloads/">http://www.intelliadmin.com/index.php/downloads/</a></p>
<p>What about that script? If you want to do it yourself without Network Administrator, here is the updated version:</p>
<p><a href="http://www.intelliadmin.com/ForceAU.dat">http://www.intelliadmin.com/ForceAU.dat</a></p>
<p>Just rename it to ForceAU.vbs, and call it like this from the command line:</p>
<p><code>cscript.exe ForceAU.vbs</code></p>
<p>Once it starts, it will zoom through and install the latest security patches:</p>
<p><img src="http://www.intelliadmin.com/images2/Windows%20Update%20Command%20Line.jpg" alt=""/></p>
<p>The script, and the plugin work with Windows XP, 2003, Windows Vista, Windows 7, and Windows 2008.</p>
<p>It does require administrator access, so if your users have a limited account you will need to either use the task scheduler, group policy, or <a href="http://www.intelliadmin.com/index.php/network-administrator/">Network Administrator</a>.</p>
<p>One other thing to note, is that it does not install service packs &#8211; So keep that in mind when using the plugin, or the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2012/01/force-install-of-security-patches-across-your-network/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Automatically disable wireless when Ethernet is available</title>
		<link>http://www.intelliadmin.com/index.php/2012/01/automatically-disable-wireless-when-ethernet-is-available/</link>
		<comments>http://www.intelliadmin.com/index.php/2012/01/automatically-disable-wireless-when-ethernet-is-available/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 15:53:02 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4641</guid>
		<description><![CDATA[Got a question from Enrico, &#8220;Good morning Steve, and Happy New Year!&#8230;I would like that when the user has a wired NIC up and running, the wireless NIC is automatically disabled, and as soon as the wired NIC disconnects, the wireless NIC activates. This prevents the user to have both NICs up and running at [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2012/01/automatically-disable-wireless-when-ethernet-is-available/" title="Permanent link to Automatically disable wireless when Ethernet is available"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Network.jpg" width="55" height="55" alt="Post image for Automatically disable wireless when Ethernet is available" /></a>
</p><p>Got a question from Enrico,</p>
<p><em>&#8220;Good morning Steve, and Happy New Year!&#8230;I would like that when the user has a wired NIC up and running, the wireless NIC is automatically disabled, and as soon as the wired NIC disconnects, the wireless NIC activates. </p>
<p>This prevents the user to have both NICs up and running at the same time and above all prevents wireless access points to collapse for too many unneeded simultaneous connections.&#8221;<br />
</em></p>
<p>Awesome question Enrico.</p>
<p>There are other reasons for wanting this too. If you have both connections running, things like file transfers, or anything that needs the extra speed of Ethernet&#8230;might end up going through the wireless instead.</p>
<p>For this question, I have created a VB Script that will receive the names of the two network cards in its command line parameters.</p>
<p>For example, if you look at your network connections:</p>
<p><img src="http://www.intelliadmin.com/images/Network%20Connections.jpg" alt="Network Connections"/></p>
<p>See the descriptions for them? That is what you will use to identify them.</p>
<p>If you wanted to watch the &#8220;Local Area Connection&#8221; adapter&#8230;and then switch the &#8220;Wireless Connection&#8221; Adapter, you would call the script like this:</p>
<p><img src="http://www.intelliadmin.com/images/Net%20Switch%20Example.jpg" alt="Watch Ethernet Example"/></p>
<p>The program will not display anything, but run in the background looking for the change. It will continue to run until the user logs out.</p>
<p>If the Local Area Connection is no longer connected, it will automatically enable the Wireless connection.</p>
<p>The reverse is true&#8230;if Local Area Connection becomes available, it will automatically disable the wireless connection.</p>
<p>The best place to run the script would be from a group policy computer configuration logon script (Not a user configuration) because it will run as local system and have the proper permission to enable and disable network cards.</p>
<p>You can get the script from here:</p>
<p>For 2003, Vista, Windows 7, and 2008:<br />
<a href="http://www.intelliadmin.com/NetSwitch.dat">NetSwitch.dat</a></p>
<p>For Windows XP:</p>
<p><a href="http://www.intelliadmin.com/NetSwitchXP.dat">NetSwitchXP.dat</a></p>
<p>Just rename to NetSwitch.vbs after downloading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2012/01/automatically-disable-wireless-when-ethernet-is-available/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Restart an application automatically</title>
		<link>http://www.intelliadmin.com/index.php/2011/06/restart-an-application-automatically/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/06/restart-an-application-automatically/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 15:53:13 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=3861</guid>
		<description><![CDATA[The emails keep coming in. Keep it up This question is from Steve (Awesome name, love it): &#8220;Hi Steve. We have a piece of software that does not run as a service. It runs like any other application. You launch it and it performs batch processing. The problem is, well, if this application dies over [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/06/restart-an-application-automatically/" title="Permanent link to Restart an application automatically"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Network.jpg" width="55" height="55" alt="Post image for Restart an application automatically" /></a>
</p><p>The emails keep coming in. Keep it up <img src='http://www.intelliadmin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>This question is from Steve (Awesome name, love it):</p>
<p>&#8220;Hi Steve. We have a piece of software that does not run as a service. It runs like any other application. You launch it and it performs batch processing. The problem is, well, if this application dies over the weekend it causes me a huge headache. It is buggy, crashes at the worst time, and it is needed to batch process items coming in from a web service. My question is, is there any way to automatically restart this app without me coming in to do it myself?&#8221;</p>
<p>Excellent question. First of all, you should never have to go into the office to fix a problem. Why aren&#8217;t you using a <a href="http://www.intelliadmin.com/index.php/enterprise-remote-control/">remote admin solution like ours</a> for situations like this?</p>
<p>I know I know, you just want the damn thing to keep running no matter how bad it is</p>
<p><img src="http://www.intelliadmin.com/images/Rusty%20Old%20Car.jpg" alt="Rusty Old Program"/></p>
<p>This can be accomplished with a small amount of VB Script. You will probably want to put this into your task scheduler to run at startup, so even if the PC gets rebooted it will automatically start again.</p>
<p>First, we need to see if an app is running. How can we do that?</p>
<p>Lets put some code together to see if notepad.exe is running:</p>
<p><code>set Service = GetObject ("winmgmts:")</p>
<p>sEXEName = "notepad.exe"<br />
bRunning = false</p>
<p>'Look for our application. Set the flag bRunning = true<br />
'If we see that it is running </p>
<p>for each Process in Service.InstancesOf ("Win32_Process")<br />
&nbsp;if Process.Name = sEXEName then<br />
&nbsp;&nbsp;bRunning=true<br />
&nbsp;End If<br />
next<br />
</code></p>
<p>The above code will look at all the running processes, and try to find &#8220;notepad.exe&#8221; if it is active then the variable bRunning will be set to true. If not, then bRunning will be set to false.</p>
<p>We are almost half way there. Now, how do we launch an application from VB Script?</p>
<p><code>set Shell = WScript.CreateObject("WScript.Shell")</p>
<p>sEXEName = "Notepad.exe"<br />
sApplicationPath = "c:\windows\system32\"</p>
<p>Shell.Run sApplicationPath &#038; sEXEName<br />
</code></p>
<p>Now we have both parts that we need. 1 &#8211; Detect if an app is not running, and 2 &#8211; Launch of that is true. </p>
<p>Here is the final script:</p>
<p><code></p>
<p>set Service = GetObject ("winmgmts:")<br />
set Shell = WScript.CreateObject("WScript.Shell")</p>
<p>sEXEName = "notepad.exe"<br />
sApplicationPath = "c:\windows\system32\"</p>
<p>'Loop until the system is shutdown or user logs out<br />
while true<br />
&nbsp;bRunning = false</p>
<p>&nbsp;'Look for our application. Set the flag bRunning = true<br />
&nbsp;'If we see that it is running </p>
<p>&nbsp;for each Process in Service.InstancesOf ("Win32_Process")<br />
&nbsp;&nbsp;if Process.Name = sEXEName then<br />
&nbsp;&nbsp;&nbsp;bRunning=true<br />
&nbsp;&nbsp;End If<br />
&nbsp;next</p>
<p>'Is our app running?</p>
<p>if (not bRunning) then<br />
&nbsp;'No it is not, launch it<br />
&nbsp;Shell.Run sApplicationPath &#038; sEXEName<br />
end if</p>
<p>'Sleep a while so we do not hog the cpu<br />
WScript.Sleep(2000)</p>
<p>wend<br />
</code></p>
<p><b>Don&#8217;t copy and paste&#8230;download it from here:</p>
<p><a href="http://www.intelliadmin.com/ApplicationRestart.dat">ApplicationRestart.dat</a></b></p>
<p>Make sure you rename it to .vbs</p>
<p>To change it to fit your needs, fill sApplicationPath and sEXEName with the name and path of the program you want to monitor. Launch it from a logon script, or the task scheduler and you should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/06/restart-an-application-automatically/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0 Getting Started Links</title>
		<link>http://www.intelliadmin.com/index.php/2010/06/powershell-2-0-getting-started-links/</link>
		<comments>http://www.intelliadmin.com/index.php/2010/06/powershell-2-0-getting-started-links/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 07:29:50 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=2313</guid>
		<description><![CDATA[I have been avoiding it for a long time. I know batch files, and VB script so well that I am not in the mood to learn a totally different scripting language. As each day passes Microsoft is slowly phasing out their support for VB Script. Eventually Power Shell will be the only way to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I have been avoiding it for a long time. I know batch files, and VB script so well that I am not in the mood to learn a totally different scripting language.</p>
<p>As each day passes Microsoft is slowly phasing out their support for VB Script. Eventually Power Shell will be the only way to get admin scripts to run on your Windows Box.</p>
<p>While I was browsing TechNet, I found some great likes that can help you get up to speed:</p>
<p><a href="http://blogs.technet.com/b/csps/archive/2010/06/06/psrefstart.aspx">Getting started with PowerShell 2.0</a> &#8211; A perfect place to start creating your first script.</p>
<p><a href="http://blogs.technet.com/b/csps/archive/2010/06/06/psrefpiping.aspx">Piping and The Pipeline</a> &#8211; Shows you how to string PowerShell scripts together</p>
<p><a href="http://blogs.technet.com/b/csps/archive/2010/06/06/psreftab.aspx">Tab Expansion</a> &#8211; You have seen it before. Press Tab at the command line and it automatically finishes your thought. Same for PowerShell</p>
<p><a href="http://blogs.technet.com/b/csps/archive/2010/06/06/psrefshortcuts.aspx">Shortcut Keys</a> &#8211; Learn how to use keyboard shortcuts that will save you time</p>
<p><a href="http://blogs.technet.com/b/csps/archive/2010/06/06/psrefremoting.aspx">Remoting</a> &#8211; Run your scripts across the network.</p>
<p>The last one is my fav. Simply because PowerShell makes remote admin so much easier (Once you get it configured).</p>
<p>To get a PowerShell session with a remote computer, type:</p>
<p><code>Enter-PSSession -ComputerName {HOSTNAME}</code></p>
<p>Where {HOSTNAME} is the name of the remote computer.</p>
<p>If remote administration is not enabled on the remote machine, you will see an error like this:</p>
<p><img src="http://www.networksteve.com/images/Remote%20Administration%20Error%20201006.jpg" alt="Remote Administration Error"/></p>
<p>Powershell has a built-in command to enable remote admin:</p>
<p><code>winrm quickconfig</code></p>
<p>Execute the above command on the remote system, and it will add the proper firewall exceptions for your remote session to get through.</p>
<p>Now, to kill that process &#8211; get the remote session open and this command will do the trick:</p>
<p><code>Stop-Process -processname notepad</code></p>
<p>It kills any open copy of notepad on the remote system.</p>
<p>Clearly, PowerShell is a whole new experience. Not happy I have to re-learn everything, but it does seem like a few commands can go a long way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2010/06/powershell-2-0-getting-started-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Network Administrator 3.0 Beta</title>
		<link>http://www.intelliadmin.com/index.php/2009/09/network-administrator-30-beta/</link>
		<comments>http://www.intelliadmin.com/index.php/2009/09/network-administrator-30-beta/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 18:14:32 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Beta]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/blog/?p=905</guid>
		<description><![CDATA[Purchase Network Administrator 2.9 for only $99 per administrator (50% off since you are a reader of my blog), and when it is released you will receive 3.0 Free. Just follow this special link We have been hard at work building a new version of Network Administrator, and have been taking many suggestions from you. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><i>Purchase Network Administrator 2.9 for only $99 per administrator (50% off since you are a reader of my blog), and when it is released you will receive 3.0 Free. <br />
<a href="http://sites.fastspring.com/intelli/product/networkadmin?coupon=READER30">Just follow this special link</a></i></p>
<p>We have been hard at work building a new version of Network Administrator, and have been taking many suggestions from you.</p>
<p>Here is a screen shot of the main form:</p>
<p><img src="http://www.intelliadmin.com/images/Network%20Administrator%203.0.jpg" alt="Network Administrator" /></p>
<p>The first thing we did was make the actions multi-threaded. Currently the system only works on one machine at a time.</p>
<p>Silly as this sounds, it was due to a limitation in the Remote Registry service with threads &#8211; We found a way around this problem.</p>
<p>It means you can reboot all of those computers in record time.</p>
<p><img src="http://www.intelliadmin.com/images/Network%20Administrator%203.0%20Progress.jpg" alt="Network Administrator Progress" /></p>
<p>Plugins, Plugins, and Plugins. It seems kind of crazy that we did not do this earlier, but the current version of Network Administrator does not have any plugin system. It makes it difficult to add new actions. In our redesign we have added a fantastic plugin system:</p>
<p><img src="http://www.intelliadmin.com/images/Network%20Administrator%20Plugin%20Selection.jpg" alt="Network Administrator Plugin Selection" /></p>
<p>Best of all, when you purchase a license, new plugins will be automatically downloaded to you for maximum plugin goodness</p>
<p><img src="http://www.intelliadmin.com/images/IntelliAdmin%20Update%20System.jpg" alt="IntelliAdmin Update System"></p>
<p>What else will you see in the new version? It depends &#8211; on you. What plugins would you like to see in 3.0? We will take the top 10 ideas and put them in the final version. Send your ideas to <a href="mailto:plugins@intelliadmin.com">plugins@intelliadmin.com</a></p>
<p>If you purchase Network Administrator 2.9 today, you will get 3.0 for free. In addition, since you are a valued reader of my blog &#8211; you can get it for half price!</p>
<p><a href="http://sites.fastspring.com/intelli/product/networkadmin?coupon=READER30">Just follow this link</a></p>
<p>Want to part of the 3.0 beta program? Then <a href="http://visitor.constantcontact.com/d.jsp?m=1102324226745&amp;p=oi">Sign up here</a> &#8211; We will release our first public beta in about two weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2009/09/network-administrator-30-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write a script to find and delete a file</title>
		<link>http://www.intelliadmin.com/index.php/2009/06/write-a-script-to-find-and-delete-a-file/</link>
		<comments>http://www.intelliadmin.com/index.php/2009/06/write-a-script-to-find-and-delete-a-file/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 12:30:38 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/blog/?p=684</guid>
		<description><![CDATA[I distributed a test version of Remote Control 4.0 across our network last week, and since it was a special debug version, it created a large number of files named debuglog.dat. I wanted an easy way to find and delete these using a batch file. I researched and was able to take parts of other [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I distributed a test version of <a href="http://www.intelliadmin.com/RemoteControl3.htm">Remote Control 4.0</a> across our network last week, and since it was a special debug version, it created a large number of files named debuglog.dat.</p>
<p>I wanted an easy way to find and delete these using a batch file. I researched and was able to take parts of other scripts to build what I needed.</p>
<p>The first step was to identify all of the local drives on the system. I know that this is available in the registry key HKEY_LOCAL_MACHINE\System\MountedDrives</p>
<p>Using the reg command, I can get this by calling:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
reg query HKLM\SYSTEM\MountedDevices</font></p>
<p>And using the find command I can pull out only the devices with dos drive letters:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
reg query HKLM\SYSTEM\MountedDevices^|find /i &#8220;\DosDevices\&#8221;</font></p>
<p>Still, this is not enough for our task. Here is what we get when calling the script:</p>
<p><img src="http://www.intelliadmin.com/images/Find%20and%20Delete%2020090526%20Batch.jpg" alt="Find and Delete"/></p>
<p>Lots of binary data we do not need</p>
<p>We can take this output, and feed it through the &#8220;for&#8221; command, and call a function for each drive letter:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
for /f &#8220;tokens=1&#8243; %%x in (&#8216;reg query HKLM\SYSTEM\MountedDevices^|find /i &#8220;\DosDevices\&#8221;&#8216;) do echo %%x</font></p>
<p>Now, we get a list of the drives, minus the binary data. We can use that to call a function that will parse out the \DosDevices\<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
for /f %34tokens=1%34 %%x in (&#8216;reg query HKLM\SYSTEM\MountedDevices^%7cfind /i %34\DosDevices\%34&#8242;) do call <img src='http://www.intelliadmin.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> eleteFileSub %%x<br />
goto endScript <img src='http://www.intelliadmin.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> eleteFileSub<br />
set LocalDrive=%1<br />
set LocalDrive=%LocalDrive:~-2%<br />
echo %Drive%<br />
goto endScript<br />
:endScript </font></p>
<p>With that script, we get a complete list of local drives. Hmm&#8230;starting to look good:</p>
<p><img src="http://www.intelliadmin.com/images/Drive%20Letters%20Batch%20File%2020090526.jpg" alt="Local Drive Letters"></p>
<p>Now. What next? Well, we want to search each local drive for our file, and then delete it. For safety reasons, I am only going to echo the file names &#8211; I want you to think real hard before doing this..since the wrong move and you could wipe out important files.</p>
<p>Again, the &#8216;for&#8217; command is a great way to do this:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
for /f &#8220;tokens=1 delims=*&#8221; %%z in (&#8216;dir &#8220;LocalDrive%\SomeFile.txt&#8221; /s /b&#8217;) do echo del &#8220;%%z&#8221;</font></p>
<p>Replace <b>SomeFile.txt</b> with the file you want to remove.</p>
<p>This will pull out the filename in a full directory search of the specified drive and echo it. If you want to actually delete the file you will need to remove the &#8220;echo&#8221;:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
for /f &#8220;tokens=1 delims=*&#8221; %%z in (&#8216;dir &#8220;LocalDrive%\<b>SomeFile.txt</b>&#8221; /s /b&#8217;) do <b>echo</b> del &#8220;%%z&#8221;</font></p>
<p>Now, putting the whole thing together:<br />
<font style="font-family: Courier New, Courier, monospace; color: blue"><br />
@echo off<br />
for /f &#8220;tokens=1&#8243; %%x in (&#8216;reg query HKLM\SYSTEM\MountedDevices^|find /i &#8220;\DosDevices\&#8221;&#8216;) do call :deleteSub %%x<br />
goto endSub<br />
:deleteSUb<br />
set LocalDrive=%1<br />
set LocalDrive=%LocalDrive:~-2%<br />
for /f &#8220;tokens=1 delims=*&#8221; %%z in (&#8216;dir &#8220;%Drive%\<b>Some File.txt</b>&#8221; /s /b&#8217;) do echo del &#8220;%%z&#8221;<br />
goto endSub<br />
:endSub<br />
</font></p>
<p><a href="http://ftp.intelliadmin.com/FindAndDelete.dat">Text version here if you have copy-paste issues</a></p>
<p>Make sure you do lots of testing before you pull the trigger and remove the &#8220;echo&#8221; statement. I wouldn&#8217;t want you to blow away the wrong files <img src='http://www.intelliadmin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2009/06/write-a-script-to-find-and-delete-a-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

