<?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; BAT Files</title>
	<atom:link href="http://www.intelliadmin.com/index.php/category/bat-files/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>Defrag computers when they are idle</title>
		<link>http://www.intelliadmin.com/index.php/2012/01/defrag-computers-when-they-are-idle/</link>
		<comments>http://www.intelliadmin.com/index.php/2012/01/defrag-computers-when-they-are-idle/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 16:28:14 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4657</guid>
		<description><![CDATA[This week we have a question from Vladimir: &#8220;Hello Steve, Happy New year to you and all the best in the new 2012. I&#8217;m battling here with fragmentation disk problems and I&#8217;m wondering; Is there a way to run a defragmentation process during night hours when all machines are idling? Can it be scripted so [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2012/01/defrag-computers-when-they-are-idle/" title="Permanent link to Defrag computers when they are idle"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/defrag.jpg" width="64" height="61" alt="Post image for Defrag computers when they are idle" /></a>
</p><p>This week we have a question from Vladimir:</p>
<p><em>&#8220;Hello Steve,<br />
Happy New year to you and all the best in the new 2012.</p>
<p>I&#8217;m battling here with fragmentation disk problems and I&#8217;m wondering;<br />
Is there a way to run a defragmentation process during night hours when all machines are idling? Can it be scripted so you can add it to a scheduler task?&#8221;</em></p>
<p>Yes&#8230;we could just go through the manual steps of creating this scheduled task, but Vladimir wants to know if we can easily script it.</p>
<p>The answer is a definite yes. In fact, it is easier to script this than to suffer through all of the windows and settings of the task scheduler.</p>
<p>To add a scheduled task, you just need to call it like this from the command line:</p>
<p><code>schtasks /create</code></p>
<p>Now, of course that needs some more options.</p>
<p>We want it to run only when the computer is idle, and since we want it to run after hours, we want to rule out lunch&#8230;so lets tell it to only run after two hours of inactivity.</p>
<p>Here are the options we will need:</p>
<p><code>/tr  = The path to the application to run<br />
/tn = The name of the task<br />
/ru = User to run the task as<br />
/sc = When to run the task<br />
/i = The number of idle minutes to wait</code></p>
<p>This is what our command to add the task would look like:</p>
<p><code>schtasks /create /ru system /sc onidle /i 120 /tn Defrag /tr "%systemroot%\system32\defrag.exe c:"</code></p>
<p>This command line can be translated to: </p>
<p>Create a task named &#8216;Defrag&#8217; that will run the defrag program under the system account &#8211; only when the computer has been idle for 120 minutes</p>
<p>After you run the task, it will add it:</p>
<p><img src="http://www.intelliadmin.com/images2/Add%20Defrag%20Task.jpg" alt="Script Scheduled Task"></p>
<p>You can verify by browsing over to scheduled tasks:</p>
<p><img src="http://www.intelliadmin.com/images2/New%20Defrag%20Task.jpg" alt="New Scheduled Task"></p>
<p>That is all there is to it. Now when the system is idle for more than two hours, it will start a defrag of the c drive. This syntax works on Windows XP through Windows 7 / 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2012/01/defrag-computers-when-they-are-idle/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create a menu for your batch file</title>
		<link>http://www.intelliadmin.com/index.php/2011/11/create-a-menu-for-your-batch-file/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/11/create-a-menu-for-your-batch-file/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 16:46:14 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4494</guid>
		<description><![CDATA[I got a question from Justin this week: &#8220;Hi steve, Have a few scripts that I use for regular admin work. I want to combine them with a simple menu. I was wondering if there was an easy way to make a menu in a batch file.&#8221; Yes there is Justin, and it is actually [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/11/create-a-menu-for-your-batch-file/" title="Permanent link to Create a menu for your batch file"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/command.jpg" width="64" height="54" alt="Post image for Create a menu for your batch file" /></a>
</p><p>I got a question from Justin this week:</p>
<p><em>&#8220;Hi steve,</p>
<p>Have a few scripts that I use for regular admin work. I want to combine them with a simple menu. I was wondering if there was an easy way to make a menu in a batch file.&#8221;<br />
</em></p>
<p>Yes there is Justin, and it is actually quite simple.</p>
<p>The SET command is perfect for this. When you call SET /P from the command line it will take a line of input and set it to a variable.</p>
<p>So if you had three options in your batch file like this:<br />
<code><br />
echo Press 1 for Option1<br />
echo Press 2 for Option2<br />
echo Press 3 for Option3<br />
echo Press 4 to Exit<br />
</code></p>
<p>You could put the set command right after it:<br />
<code><br />
set /P OPT=Please make a selection and press enter</code></p>
<p>This would print the text &#8220;Please make a selection..&#8221; and then store the users input after they press enter &#8211; into the %OPT% variable.</p>
<p>Once that happens we can use a few if statements to conditionally execute. </p>
<p>Here is it all together:</p>
<p><code></p>
<p>@ECHO OFF<br />
CLS<br />
ECHO 1 - Option 1<br />
ECHO 2 - Option 2<br />
ECHO 3 - Option 4<br />
ECHO 4 - Exit</p>
<p>SET /P OPT=Please make a selection, and press enter:</p>
<p>if %OPT%==1 GOTO OPTION1<br />
if %OPT%==2 GOTO OPTION2<br />
if %OPT%==3 GOTO OPTION3</p>
<p>GOTO EXIT</p>
<p>:OPTION1</p>
<p>ECHO Executing option1!</p>
<p>GOTO EXIT</p>
<p>:OPTION2</p>
<p>ECHO Executing option2!</p>
<p>GOTO EXIT</p>
<p>:OPTION3</p>
<p>ECHO Executing option3!</p>
<p>GOTO EXIT</p>
<p>:EXIT<br />
</code></p>
<p>Save the file as menu.bat and run it</p>
<p>That is all there is to it.  </p>
<p>Just change the echo statements to the batch commands you want to execute for each option, and you have an easy to use menu from the command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/11/create-a-menu-for-your-batch-file/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Copy files that are in use</title>
		<link>http://www.intelliadmin.com/index.php/2011/11/copy-files-that-are-in-use/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/11/copy-files-that-are-in-use/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:04:47 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4368</guid>
		<description><![CDATA[A few weeks back I wrote about deleting files that are in use What about copying them so you can back them up? I found a tool that will do just that. It is called hobocopy. Not to be confused with robocopy, hobocopy takes advantage of a system within windows called Volume Shadow Copy. This [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/11/copy-files-that-are-in-use/" title="Permanent link to Copy files that are in use"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Drive.jpg" width="55" height="45" alt="Post image for Copy files that are in use" /></a>
</p><p>A few weeks back <a href="http://www.intelliadmin.com/index.php/2011/09/move-or-delete-files-that-are-always-in-use/">I wrote about deleting files that are in use</a> </p>
<p>What about copying them so you can back them up?</p>
<p>I found a tool that will do just that. </p>
<p>It is called hobocopy.</p>
<p>Not to be confused with <a href="http://www.intelliadmin.com/index.php/2006/01/robocopy-is-an-administrators-best-friend/">robocopy</a>, hobocopy takes advantage of a system within windows called Volume Shadow Copy. This allows you to &#8216;shadow&#8217; files so you can back them up, even while they are in use.</p>
<p>Normally this is just used by backup apps, or the<br />
&#8220;Previous Versions&#8221; feature of windows</p>
<p><img src="http://www.intelliadmin.com/images/Previous%20Versions%20Windows%207.jpg" alt="Previous Versions"/></p>
<p>To get started, visit the hobocopy download page:</p>
<p><a href="https://github.com/candera/hobocopy/downloads">https://github.com/candera/hobocopy/downloads</a></p>
<p>Just make sure you get the right one. If you have the 32 bit version of Windows 7..then get the 32 bit version. </p>
<p>The three release versions at the bottom of the page are the ones you want to look at. </p>
<p>If you do download the wrong one, most likely it will return an error when trying to use it. This is because it cannot properly hook into the Volume Shadow Copy system.</p>
<p>Now, on to our task. To copy a folder that contains files that are in use, simply call it like this:</p>
<p><code>hobocopy [source] [dest]</code></p>
<p>If you want to get some of the incremental copy features that you see in robocopy, you will first need to make a full copy like this:</p>
<p><code>hobocopy c:\source c:\dest /statefile=inc.state</code></p>
<p>This will create a file named inc.state that the incremental copy can use to determine what changed.</p>
<p>Once that full copy is complete, you can run an incremental by referencing the same state file:</p>
<p><code>hobocopy c:\source d:\dest /statefile=inc.state /incremental</code></p>
<p>Now it will only copy files that have changed.</p>
<p>One word of warning with all of this. Not all &#8216;files in use&#8217; are equal. It is possible that the file could be quite old if the application using it never releases its lock. </p>
<p>MSSQL database files fit this description. In addition, applications that don&#8217;t properly lock and unlock their files may cause you to copy a file that is in a transient state &#8211; in other words corrupted.</p>
<p>Make sure you test this out before someone comes to your desk and asks, &#8220;Um, do we backup our files?&#8221;</p>
<p><img src="http://www.intelliadmin.com/images/Do%20we%20backup%20our%20files.jpg" alt="Do we make backups?"></p>
<p>The main hobocopy website can be found here:</p>
<p><a href="http://candera.github.com/hobocopy/">http://candera.github.com/hobocopy/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/11/copy-files-that-are-in-use/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Download From a batch file</title>
		<link>http://www.intelliadmin.com/index.php/2011/09/download-from-a-batch-file/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/09/download-from-a-batch-file/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 14:59:27 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4225</guid>
		<description><![CDATA[Got a question from Nathan: &#8220;Steve, we have a file we need to download from a website once a week. Since I am the only one in the IT department, they have made it my job to get this file and put it on a public share every Friday. Is there any way I could [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/09/download-from-a-batch-file/" title="Permanent link to Download From a batch file"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Command.jpg" width="64" height="54" alt="Post image for Download From a batch file" /></a>
</p><p>Got a question from Nathan:</p>
<p>&#8220;Steve, we have a file we need to download from a website once a week. Since I am the only one in the IT department, they have made it my job to get this file and put it on a public share every Friday. Is there any way I could download it automatically?&#8221;</p>
<p>That is a great question. There are a few ways you can do this, but my favorite is to use a free and open source tool called CURL. </p>
<p>It is a command line program that allows you to get web pages, and binary files from HTTP, HTTPS, and FTP servers.</p>
<p>You can download a free copy from here:</p>
<p><a href="http://curl.haxx.se/latest.cgi?curl=win32-ssl">http://curl.haxx.se/latest.cgi?curl=win32-ssl</a></p>
<p>There are so many features and options, you could probably write a book on this tool. I will show just one way to use it.</p>
<p>Our friend Nathan wants to download a file from his batch file. </p>
<p>Lets say the URL of the file is</p>
<p><code><a href="http://ftp.intelliadmin.com/setupex.exe">http://ftp.intelliadmin.com/setupex.exe</a></code></p>
<p>And we want to save it to </p>
<p><code>\\server1\public\data\setupex.exe</code></p>
<p>Our CURL command line would look like this in our batch:</p>
<p><code>curl --location http://ftp.intelliadmin.com/setupex.exe > \\server1\public\data\setupex.exe</code></p>
<p>That one line is all we need. The &#8211;location option tells CURL to follow redirects. Without it, if the target page is redirected, you will only get the redirect notice &#8211; not the file you wanted to download.</p>
<p>Add it to the task scheduler in Windows, and have it run once a week. </p>
<p>No more downloading for Nathan. He can spend his time reading my old blog articles <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/2011/09/download-from-a-batch-file/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Set default printer based on gateway</title>
		<link>http://www.intelliadmin.com/index.php/2011/08/set-default-printer-based-on-gateway/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/08/set-default-printer-based-on-gateway/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 15:10:40 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4076</guid>
		<description><![CDATA[I got a question from Mike this week: &#8220;Hi Steve. I have a question. We have three remote branches and users move from branch to branch with their laptops. Is there any way to change their default printer when they login at each branch?&#8221; Further discussions with Mike gave me more info: Most of the [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/08/set-default-printer-based-on-gateway/" title="Permanent link to Set default printer based on gateway"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Printer.jpg" width="112" height="99" alt="Post image for Set default printer based on gateway" /></a>
</p><p>I got a question from Mike this week:</p>
<p><i>&#8220;Hi Steve. I have a question. We have three remote branches and users move from branch to branch with their laptops. Is there any way to change their default printer when they login at each branch?&#8221;</i></p>
<p>Further discussions with Mike gave me more info: Most of the latops are running Windows XP, each branch has their own DHCP server, and each branch uses a different gateway.</p>
<p>If he was using Windows 7 on all those laptops, we would not need a script &#8211; this feature is built in.</p>
<p>My method will use VBScript. Lets start out by creating a script that will get the current default gateway:</p>
<p><code>Function GetDefaultGateway<br />
&nbsp;Dim Adapter, Adapters, WMI</p>
<p>&nbsp;GetDefaultGateway = ""</p>
<p>&nbsp;Set WMI = GetObject("winmgmts:\\.\root\cimv2") </p>
<p>&nbsp;Set Adapters = WMI.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") </p>
<p>&nbsp;For Each Adapter In Adapters<br />
&nbsp;&nbsp;If Not IsNull(Adapter.DefaultIPGateway) Then<br />
&nbsp;&nbsp;&nbsp;If Not Adapter.defaultIPGateway(0) = "0.0.0.0" Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;GetDefaultGateway = Adapter.DefaultIPGateway(0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Exit For<br />
&nbsp;&nbsp;&nbsp;End If<br />
&nbsp;&nbsp;End If<br />
&nbsp;Next<br />
End Function<br />
</code></p>
<p>Our function above &#8220;GetDefaultGateway&#8221; will loop through our network interfaces and find the one with its gateway set&#8230;when it finds that it will exit and return it as a string.</p>
<p>Now, we need to check the gateway, and set the default printer based on what we see:</p>
<p><code>Dim oPrinter</p>
<p>Set oPrinter = CreateObject("WScript.Network") </p>
<p>Select Case GetDefaultGateway<br />
&nbsp;Case "192.168.0.1"<br />
&nbsp;&nbsp;oPrinter.SetDefaultPrinter "\\ServerName\Branch1Printer"<br />
&nbsp;Case "192.168.1.1"<br />
&nbsp;&nbsp;oPrinter.SetDefaultPrinter "\\ServerName\Branch2Printer"<br />
&nbsp;Case "192.168.2.1"<br />
&nbsp;&nbsp;oPrinter.SetDefaultPrinter "\\ServerName\Branch3Printer"<br />
&nbsp;Case else<br />
&nbsp;&nbsp;oPrinter.SetDefaultPrinter "Xerox Phaser 6130N PS"<br />
end case<br />
</code></p>
<p>So there we have it. If the user&#8217;s gateway matches one of our cases, we set the appropriate default printer&#8230;if nothing matches we set it to the Xerox printer.</p>
<p>Notice that you can provide full printer names, or a path to its network share &#8211; either will work.</p>
<p>The full script can be found <a href="http://www.intelliadmin.com/DefaultPrinterByGateway.dat"">here</a></p>
<p>Just rename to .vbs, and add your own settings and you should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/08/set-default-printer-based-on-gateway/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create a conditional batch file &#8211; Based on OS, or Computer Name</title>
		<link>http://www.intelliadmin.com/index.php/2011/07/create-a-conditional-batch-file-based-on-os-or-computer-name/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/07/create-a-conditional-batch-file-based-on-os-or-computer-name/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 17:03:40 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Free]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=4048</guid>
		<description><![CDATA[I got a question from one of our customers this week, &#8220;Is there a way to run profile generator based on its workstation name? We want cached mode activated for laptops but not desktops. Or can you advise how this can be determined with the batch file?&#8221; Actually we have had a tool internally that [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/07/create-a-conditional-batch-file-based-on-os-or-computer-name/" title="Permanent link to Create a conditional batch file &#8211; Based on OS, or Computer Name"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Command.jpg" width="64" height="54" alt="Post image for Create a conditional batch file &#8211; Based on OS, or Computer Name" /></a>
</p><p>I got a question from one of our customers this week,</p>
<p><i>&#8220;Is there a way to run <a href="http://www.intelliadmin.com/index.php/profile-generator/">profile generator</a> based on its workstation name? We want cached mode activated for laptops but not desktops. Or can you advise how this can be determined with the batch file?&#8221;</i></p>
<p>Actually we have had a tool internally that we have used for a long time. I decided to clean it up, and add it to our free tools.</p>
<p>It is called &#8220;IsComputer.exe&#8221; and you can get it from our <a href="http://www.intelliadmin.com/index.php/downloads/">downloads page</a></p>
<p>Here is how it works. You can give it two conditions &#8211; The version of Windows, or the name of the computer. </p>
<p>Lets say I want part of my script to only run on computers that are not Vista and above (Windows 2003, XP, and 2000) and start with the name LAPTOP:</p>
<p><code>IsComputer /name:LAPTOP* /os:CLASSIC</code></p>
<p>Or, I want it to only run on Windows 2003 computers:</p>
<p><code>IsComputer /OS:Windows2003</code></p>
<p>Or, maybe just computers that have &#8216;server&#8217; in their name:</p>
<p><code>IsComputer /Name:*server*</code></p>
<p>Those are just a few options &#8211; a complete list of options can be viewed by running it from the command line. </p>
<p>How do we get it to work with our batch file?</p>
<p>If a condition matches, the program will return 1. If it does not match it will return 0. Here is how we can create a simple script that will output &#8216;hello&#8217; if we have a match:</p>
<p><code>@echo off<br />
IsComputer /OS:Classic /quiet /name:rack*<br />
if ERRORLEVEL 1 goto RUN_SCRIPT<br />
if ERRORLEVEL 0 goto EXIT_SCRIPT</p>
<p>:RUN_SCRIPT</p>
<p>REM Your conditional batch statements would go here</p>
<p>echo Hello</p>
<p>:EXIT_SCRIPT<br />
</code></p>
<p>This example script will output &#8216;hello&#8217; if the computer is running Windows 2003, and the name of the computer starts with &#8216;rack&#8217;. </p>
<p>You could put the batch file commands you want to execute right where the &#8220;echo hello&#8221; statement is. </p>
<p>Got a question, or an idea for a free tool? Let me know by mailing <a href="mailto:support@intelliadmin.com">support@intelliadmin.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/07/create-a-conditional-batch-file-based-on-os-or-computer-name/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Notify users when their password expires</title>
		<link>http://www.intelliadmin.com/index.php/2011/05/notify-users-when-their-password-expires/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/05/notify-users-when-their-password-expires/#comments</comments>
		<pubDate>Fri, 06 May 2011 16:33:57 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Group Policy]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=3282</guid>
		<description><![CDATA[I have been getting lots of questions from everyone, and that is great This week I got a question from Charles, &#8220;Hello Steve, I have a problem, I need to run a VB Script that will tell users that their password needs to be changed in x days. The Windows 7 balloon is not effective, [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/05/notify-users-when-their-password-expires/" title="Permanent link to Notify users when their password expires"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Command.jpg" width="64" height="54" alt="Post image for Notify users when their password expires" /></a>
</p><p>I have been getting lots of questions from everyone, and that is great</p>
<p>This week I got a question from Charles,</p>
<p><i>&#8220;Hello Steve, </p>
<p>I have a problem, I need to run a VB Script that will tell users that their password needs to be changed in x days. The Windows 7 balloon is not effective, and users miss it. Also, I do not want it to slow down the login.  So what options do I have left?&#8221;<br />
</i></p>
<p>This is an excellent question. Other versions of windows might not even tell you. </p>
<p>For example: A user could leave their system on for days and days, and then cross the threshold of the password expiration date &#8211; suddenly nothing works for them.</p>
<p>You know what that means &#8211; another call to the help desk!</p>
<p><img src="http://www.intelliadmin.com/images/Help%20Desk%20Call%20201105.jpg" alt="Help Desk Call"/></p>
<p>I have a good trick to filling all of your requirements. I have translated them to:</p>
<p>1. Make sure the users logon is swift, and not interrupted by a password expiration notice (Especially because windows just told them about it!)</p>
<p>2. While they are using windows, make it clear that their password expired. Don&#8217;t depend on Windows to properly notify them.</p>
<p>3. Do all of this from a script, no extra programs required</p>
<p>I think we can make that happen. First, we need a script to see if and when the users password expires. I found one <a href="http://msdn.microsoft.com/en-us/library/ms974598.aspx">that Microsoft has provided</a>, and I have modified it to suit our needs. </p>
<p>The script has one function &#8211; PasswordDaysLeft. You call it, and it returns the number of days left before the password expires. If the function returns 99999 then the password never expires.</p>
<p>For example, if we wanted to know that in 10 days or less the password would expire, we would call it like this:<br />
<code><br />
if (PasswordDaysLeft() <= 10) then<br />
&nbsp;MsgBox("Your password will expire in " &#038; PasswordDaysLeft() &#038; " days!")<br />
end if<br />
</code></p>
<p>So now we have the ability to check for password expiration. But what about the original request? We don't want it to pop up at startup, but later. </p>
<p>Here is how we can get our script to do that:</p>
<p>We will loop in our script, and only check every 5 minutes. In addition, we will only start checking 20 minutes after the user logs in:<br />
<code><br />
'Sleep for 20 minutes<br />
WScript.Sleep(20 * 1000 * 60)</p>
<p>bRunning = TRUE<br />
'20 minutes is up, check every 5 min to see if password is too old<br />
while (bRunning)<br />
&nbsp;if (PasswordDaysLeft() <= 10) then<br />
&nbsp;MsgBox("Your password is about to expire. Please log off right now and change it")<br />
&nbsp;bRunning = FALSE<br />
&nbsp;end if<br />
&nbsp;WScript.Sleep(5 * 1000 * 60)<br />
wend<br />
</code></p>
<p>This will stay running until the password expires, or the user shuts down or logs off. Once the user is notified, it will exit and not bother them again.</p>
<p>Now we have most of what we need:</p>
<p>-A function that tells us how many days before a password expires<br />
-A script to check it. </p>
<p>How do we get it to run in the background?</p>
<p>That is easy. From the users logon bat file we call our VB Script like this:</p>
<p><code>start wscript \\server\share\PasswordExpires.vbs</code></p>
<p>This tells the BAT file to fire up our script, but not to wait for it.</p>
<p>So here is what happens:</p>
<p>The user logs in, the script is launched into the background. It silently waits for 20 minutes, and then on 5 minute intervals it checks if the password expired. If it did, then the user gets a notification and it quits.</p>
<p>It think that covers everything. The logon is quick, since it launches our script in the background and lets the user get right to their business. </p>
<p>You can download the zip file with the VBS file, and an example BAT logon script here:</p>
<p><a href="http://www.intelliadmin.com/PasswordExpires.zip">http://www.intelliadmin.com/PasswordExpires.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/05/notify-users-when-their-password-expires/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Backup Outlook from the command line</title>
		<link>http://www.intelliadmin.com/index.php/2011/04/backup-outlook-from-the-command-line/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/04/backup-outlook-from-the-command-line/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 13:54:48 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[Exchange 2003]]></category>
		<category><![CDATA[Exchange 2007]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=3256</guid>
		<description><![CDATA[Jennifer, sent me a question last week: Steve, Got a question for you. I have a small network of about 10 laptops. All of my users store their email in PST files in Outlook. I want to have an icon on their desktop that they can click to backup Outlook before they leave for the [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/04/backup-outlook-from-the-command-line/" title="Permanent link to Backup Outlook from the command line"><img class="post_image alignleft remove_bottom_margin" src="http://www.intelliadmin.com/icons/Email.jpg" width="55" height="55" alt="Post image for Backup Outlook from the command line" /></a>
</p><p>Jennifer, sent me a question last week:</p>
<p><i>Steve, </p>
<p>Got a question for you. I have a small network of about 10 laptops. All of my users store their email in PST files in Outlook. I want to have an icon on their desktop that they can click to backup Outlook before they leave for the weekend. Is there any easy way to do this?</p>
<p>Thanks,</p>
<p>Jen<br />
</i><br />
Yes, There is a way to do this. Now it is not foolproof, but it will work most of the time.</p>
<p><img src="http://www.intelliadmin.com/images/Outlook%20Backup%20Command%20Line.jpg"/></p>
<p>First, we need our script to close Outlook, that way the PST files will not be in use. </p>
<p>We will accomplish this with a little bit of VB Script:<br />
<code><br />
Set Outlook = CreateObject("Outlook.Application")<br />
Outlook.Quit<br />
Set Outlook = Nothing<br />
</code></p>
<p>Save this as &#8220;CloseOutlook.vbs&#8221;</p>
<p>Now, we will use this script, in combination with a bat file. The bat file will run CloseOutlook.vbs, and then copy the PST files.</p>
<p>Most of the time PST files are located in the users AppData folder. We can use an environment variable to find this. </p>
<p>It is called %LOCALAPPDATA%. For our backup, we will copy it to a share named backup, and we will copy it to a folder matching the users name.</p>
<p>The copy command will look like this:<br />
<code><br />
COPY %LOCALAPPDATA%\Microsoft\Outlook\*.pst \\server\backup\%USERNAME% /y<br />
</code><br />
/y &#8211; This allows us to overwrite without being prompted.</p>
<p>So, we have both things that we need. The ability to close Outlook (So the user does not have to remember to do this), and a way to find and copy our PST files.</p>
<p>Here is what the final bat file would look like</p>
<p><code><br />
cscript.exe CloseOutlook.vbs<br />
COPY %LOCALAPPDATA%\Microsoft\Outlook\*.pst \\server\backup\%USERNAME% /y<br />
@if errorlevel 1 goto ERROR_HANDLER<br />
@goto SUCCESS<br />
:ERROR_HANDLER<br />
@echo "==================="<br />
@echo "=  Backup Failed  =<br />
@echo "==================="</p>
<p>@goto exit<br />
:SUCCESS<br />
@echo "==================="<br />
@echo "= Backup Complete =<br />
@echo "==================="</p>
<p>:EXIT<br />
pause<br />
</code><br />
I added an error handler, so the user will be notified if the copy could not complete.</p>
<p>Save it as BackupOutlook.bat and throw it on their desktop. </p>
<p>Now your users can backup their PST files &#8211; If they remember to do it <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/2011/04/backup-outlook-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Get product keys from computers across your network.</title>
		<link>http://www.intelliadmin.com/index.php/2011/04/get-product-keys-from-computers-across-your-network/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/04/get-product-keys-from-computers-across-your-network/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 05:56:25 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=3237</guid>
		<description><![CDATA[Last week I wrote about a free tool from Nirsoft &#8211; A kind reader, Mike, let me know about another one of their tools: Hey Steve, Thanks again for tips you send each week. I just wanted to point out that Nirsoft has quite a few useful tools. One of them that I use every [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/04/get-product-keys-from-computers-across-your-network/" title="Permanent link to Get product keys from computers across your network."><img class="post_image alignleft remove_bottom_margin" src="http://www.networksteve.com/icons/Command.jpg" width="64" height="54" alt="Post image for Get product keys from computers across your network." /></a>
</p><p>Last week I wrote about a free tool from <a href="http://www.nirsoft.net">Nirsoft</a> &#8211; A kind reader, Mike, let me know about another one of their tools:</p>
<p><i>Hey Steve,</p>
<p>Thanks again for tips you send each week. I just wanted to point out that Nirsoft has quite a few useful tools. One of them that I use every year for our software audit is ProduKey. It allows you to gather the product keys used on computers across your whole domain. And just like the password utility, it is free!</i></p>
<p>I checked it out, and it is a great way to grab serial numbers of Microsoft products.</p>
<p>You can use the gui interface, and just see the product keys on your own computer:</p>
<p><img src="http://www.intelliadmin.com/images/Product%20Key.jpg" alt="Product Key Information"/></p>
<p>It also has an unbelievable number of options for pulling information from other computers or even drives where windows is installed:</p>
<p><img src="http://www.intelliadmin.com/images/Product%20Key%20Source%20Options.jpg" alt="Product Key Source Options"/></p>
<p>In addition to the gui interface, you can call the application from the command line:</p>
<p><code>ProduKey.exe /stext "c:\temp\info.txt" - Output current computer product information to a file </p>
<p>ProduKey.exe /remote \\server01 /stext "c:\temp\info.txt" - Output a remote computer's product information to a file</p>
<p>ProduKey.exe /iprange 192.168.1.10 192.168.1.50 /stext "c:\temp\info.txt" - Get product information for computers in an IP range</p>
<p>ProduKey.exe /remotealldomain MyDomain /stext "c:\temp\info.txt" - Get product information for all computers within a domain<br />
</code><br />
Download it, and get a list of all the command line options here:</p>
<p><a href="http://www.nirsoft.net/utils/product_cd_key_viewer.html">http://www.nirsoft.net/utils/product_cd_key_viewer.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/04/get-product-keys-from-computers-across-your-network/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Delete files more than X Days old.</title>
		<link>http://www.intelliadmin.com/index.php/2011/03/delete-files-more-than-x-days-old/</link>
		<comments>http://www.intelliadmin.com/index.php/2011/03/delete-files-more-than-x-days-old/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 14:32:08 +0000</pubDate>
		<dc:creator>Steve Wiseman</dc:creator>
				<category><![CDATA[BAT Files]]></category>
		<category><![CDATA[Free]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://www.intelliadmin.com/?p=3125</guid>
		<description><![CDATA[On one of our servers we have a batch processing program. It is old and clunky, but it gets the job done. An irritating bug it has is that it leaves temp files around in the c:\windows\temp folder. One day we noticed the server was getting slow &#8211; finally realized that the temp folder had [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.intelliadmin.com/index.php/2011/03/delete-files-more-than-x-days-old/" title="Permanent link to Delete files more than X Days old."><img class="post_image alignleft remove_bottom_margin" src="http://www.networksteve.com/icons/Command.jpg" width="64" height="54" alt="Post image for Delete files more than X Days old." /></a>
</p><p>On one of our servers we have a batch processing program. It is old and clunky, but it gets the job done. </p>
<p>An irritating bug it has is that it leaves temp files around in the c:\windows\temp folder. </p>
<p>One day we noticed the server was getting slow &#8211; finally realized that the temp folder had over 100,000 files!</p>
<p>We don&#8217;t have the code for this program, so we can&#8217;t fix the bug. An easy fix would be to setup a scheduled task to trash that folder every night.</p>
<p><img src="http://www.intelliadmin.com/images/Oscar%20The%20Grouch.jpg" alt="Windows Trash"/></p>
<p>Oscar would like to have all those files every night, but the problem with this solution is it can cause problems with apps that actually are *using* those temp files.</p>
<p>What we needed was a way to delete files that were over 1 day old. This was enough to make sure the temp file was no longer used by any of our processing apps.</p>
<p>After searching around, I found a command line program that Microsoft included with some versions of windows. It is called &#8220;forfiles&#8221;</p>
<p>ForFiles will process a command against files and folders that match your criteria. It allows you to set wildcards, pick only folders, or only files&#8230;and more importantly it allows you to specify something like &#8220;I only want files that are more than 1 day old&#8221;</p>
<p>First, let me show you the possible command line arguments for it:</p>
<p><code><br />
/P <b>Path Name</b> - Indicates the path to start searching. The default folder is the current working directory</p>
<p>/M <b>Search Mask</b> - Searches files according to a searchmask. The default searchmask is '*' .</p>
<p>/S  <b>Sub Directories</b> Instructs forfiles to recurse into subdirectories. Like "DIR /S".</p>
<p>/C  <b>Command</b> Indicates the command to execute for each file. Command strings should be wrapped in double quotes.</p>
<p>The following variables can be used in the command string:</p>
<p> @file - returns the name of the file.<br />
 @fname   - returns the file name without extension.<br />
 @ext     - returns only the extension of the file.<br />
 @path    - returns the full path of the file.<br />
 @relpath - returns the relative path of the file.<br />
 @isdir   - returns "TRUE" if a file type is a directory, and "FALSE" for files.<br />
 @fsize   - returns the size of the file in bytes.<br />
 @fdate   - returns the last modified date of the file.<br />
 @ftime   - returns the last modified time of the file.</p>
<p>To include special characters in the command line, use the hexadecimal code for the character in 0xHH format (ex. 0x09 for tab). Internal CMD.exe commands should be preceded with "cmd /c".</p>
<p>/D <b>date</b> Selects files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date using the "yyyy/MM/dd" format; or selects files with a last modified date greater than or equal to (+) the current date plus "dd" days, or less than or equal to (-) the current date minus "dd" days. valid "dd" number of days can be any number in the range of 0 - 32768."+" is taken as default sign if not specified.<br />
</code></p>
<p>Cool. It has everything we need. </p>
<p>Lets start out with the path. We want it to look in c:\windows\temp</p>
<p><code>forfiles <b style="color:black"> -p "c:\windows\temp"</b></code></p>
<p>I want to include subfolders:</p>
<p><code>forfiles -p "c:\windows\temp" <b style="color:black">-s</b></code></p>
<p>Using the date option, I tell it anything over 1 day old:</p>
<p><code>forfiles -p "c:\windows\temp" -s <b style="color:black">-d -1</b></code></p>
<p>I only want to delete the files that end with .tmp:</p>
<p><code>forfiles -p "c:\windows\temp" -s -d -1 <b style="color:black">-m *.tmp</b></code></p>
<p>And finally, the command I want to execute against the files it finds is del:</p>
<p><code>forfiles -p "c:\windows\temp" -s -d -1 -m *.tmp<br />
<b style="color:black">-c "cmd /c del /f /q @path"</b></code></p>
<p>Note the use of the @path variable &#8211; it is one of the many variables forfiles recognizes. </p>
<p>So there it is &#8211; a one line command that will delete files from our temp folder over 1 day old:</p>
<p><code>forfiles -p "c:\windows\temp" -s -d -1 -m *.tmp  -c "cmd /c del /f /q @path"</code></p>
<p>If your copy of windows does not have forfiles, you can download it from the Microsoft FTP Server here:</p>
<p><a href="ftp://ftp.microsoft.com/ResKit/y2kfix/x86/">ftp://ftp.microsoft.com/ResKit/y2kfix/x86/</a></p>
<p>I am really impressed with this little utility, and the possibilities are endless. I highly suggest keeping a copy on your flash drive.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelliadmin.com/index.php/2011/03/delete-files-more-than-x-days-old/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

