<?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>Andrew Healey's Blog &#187; vbScript</title>
	<atom:link href="http://halfloaded.com/blog/tag/vbscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://halfloaded.com</link>
	<description>Smash forehead on keyboard to continue...</description>
	<lastBuildDate>Tue, 20 Jul 2010 18:11:39 +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>vbScript: Quickly determine architecture</title>
		<link>http://halfloaded.com/blog/vbscript-quickly-determine-architecture/</link>
		<comments>http://halfloaded.com/blog/vbscript-quickly-determine-architecture/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 18:10:11 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[vbScript]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[x64]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://halfloaded.com/?p=442</guid>
		<description><![CDATA[I&#8217;ve been using a routine to determine 64-bit v 32-bit workstations for some time checking the registry for the PROCESSOR_ARCHITECTURE in the HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment path. However, this was proving to be error prone. So, I just gave up that method altogether since all Windows x64 editions have a &#8220;%SystemDrive%\Program Files (x86)&#8221; directory. This makes it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://halfloaded.com/wp-content/uploads/2010/07/32-64.jpg"><img src="http://halfloaded.com/wp-content/uploads/2010/07/32-64-150x150.jpg" alt="" title="XP x64" width="150" height="150" class="alignright size-thumbnail wp-image-445" /></a>I&#8217;ve been using a routine to determine 64-bit v 32-bit workstations for some time checking the registry for the PROCESSOR_ARCHITECTURE in the HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment path.  However, this was proving to be error prone.  So, I just gave up that method altogether since all Windows x64 editions have a &#8220;%SystemDrive%\Program Files (x86)&#8221; directory.  This makes it just a quick and easy call the folderexists method of the filesystemobject.</p>
<p>The only downside is that can&#8217;t be used remotely but since most of my scripts are used in local policies, this shouldn&#8217;t be an issue.</p>
<p>Cheers!</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> is64bit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">Dim</span> filesys : <span style="color: #FF8000;">Set</span> filesys <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">Dim</span> bln64bit : bln64bit <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
	<span style="color: #0600FF;">If</span> filesys.<span style="color: #0000FF;">FolderExists</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;C:\Program Files (x86)&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">then</span> bln64bit <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
	is64bit <span style="color: #008000;">=</span> bln64bit
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;t=vbScript%3A+Quickly+determine+architecture" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;title=vbScript%3A+Quickly+determine+architecture&amp;summary=I%27ve%20been%20using%20a%20routine%20to%20determine%2064-bit%20v%2032-bit%20workstations%20for%20some%20time%20checking%20the%20registry%20for%20the%20PROCESSOR_ARCHITECTURE%20in%20the%20HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CEnvironment%20path.%20%20However%2C%20this%20was%20proving%20to%20be%20error%20prone.%20%20So%2C%20I%20just%20gave%20up%20that%20method%20altogeth&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=vbScript%3A+Quickly+determine+architecture+-+File: /data/app/webapp/functions.php<br />Line: 43<br />Message: Table 'b2l_shrinker.phurl_urls' doesn't exist&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=vbScript%3A+Quickly+determine+architecture&amp;du=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;cn=I%27ve%20been%20using%20a%20routine%20to%20determine%2064-bit%20v%2032-bit%20workstations%20for%20some%20time%20checking%20the%20registry%20for%20the%20PROCESSOR_ARCHITECTURE%20in%20the%20HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CEnvironment%20path.%20%20However%2C%20this%20was%20proving%20to%20be%20error%20prone.%20%20So%2C%20I%20just%20gave%20up%20that%20method%20altogeth" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;title=vbScript%3A+Quickly+determine+architecture" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;submitHeadline=vbScript%3A+Quickly+determine+architecture&amp;submitSummary=I%27ve%20been%20using%20a%20routine%20to%20determine%2064-bit%20v%2032-bit%20workstations%20for%20some%20time%20checking%20the%20registry%20for%20the%20PROCESSOR_ARCHITECTURE%20in%20the%20HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CEnvironment%20path.%20%20However%2C%20this%20was%20proving%20to%20be%20error%20prone.%20%20So%2C%20I%20just%20gave%20up%20that%20method%20altogeth&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/vbscript-quickly-determine-architecture/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/vbscript-quickly-determine-architecture/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22vbScript%3A%20Quickly%20determine%20architecture%22&amp;body=Link: http://halfloaded.com/blog/vbscript-quickly-determine-architecture/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%27ve%20been%20using%20a%20routine%20to%20determine%2064-bit%20v%2032-bit%20workstations%20for%20some%20time%20checking%20the%20registry%20for%20the%20PROCESSOR_ARCHITECTURE%20in%20the%20HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CEnvironment%20path.%20%20However%2C%20this%20was%20proving%20to%20be%20error%20prone.%20%20So%2C%20I%20just%20gave%20up%20that%20method%20altogeth" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/vbscript-quickly-determine-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Java via Script and Group Policy</title>
		<link>http://halfloaded.com/blog/installing-java-via-script-and-group-policy/</link>
		<comments>http://halfloaded.com/blog/installing-java-via-script-and-group-policy/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 17:39:14 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[group policy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jre]]></category>
		<category><![CDATA[vbScript]]></category>

		<guid isPermaLink="false">http://halfloaded.com/?p=437</guid>
		<description><![CDATA[Due to some software requirements, there was a need to get JRE 1.5.0_09 rolled out across our enterprise. The requirements were pretty straight forward: Only install on client operating systems (Windows 2000, Windows XP, Windows Vista and Windows 7) Detect the versions of Java installed. If 1.5.0_09 is installed, exit.  If 1.5.0_08 or less was [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://halfloaded.com/wp-content/uploads/2010/07/javalogo.png"><img src="http://halfloaded.com/wp-content/uploads/2010/07/javalogo-150x150.png" alt="" title="javalogo" width="150" height="150" class="alignright size-thumbnail wp-image-439" /></a>Due to some software requirements, there was a need to get JRE 1.5.0_09 rolled out across our enterprise.  The requirements were pretty straight forward:</p>
<ul>
<li>Only install on client operating systems (Windows 2000, Windows XP, Windows Vista and Windows 7)</li>
<li>Detect the versions of Java installed. If 1.5.0_09 is installed, exit.  If 1.5.0_08 or less was installed, install this version.  If it has a newer version, do nothing.</li>
</ul>
<p>The best way of determining the Java versions is to look in %program files%.  On 64-bit machines, this is &#8220;C:\program files (x86)\Java&#8221;.  On 32-bit, this is &#8220;C:\program files\Java&#8221;.  The script accounts for this.</p>
<p>I wanted to post this because several of the functions used are very useful.  The share hosting the jre runtime needs to have wide open read-only access so the Local System account can access share (Domain Computers).  This script can then be applied to machine accounts in group policy as a startup script.  If you want to test this, just comment out line 111.</p>
<p>Cheers!<br />
<a href='http://halfloaded.com/wp-content/uploads/2010/07/install-java.zip'>Download Compressed (.zip) script</a></p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'======================================================</span>
<span style="color: #008080; font-style: italic;">' VBScript Source File</span>
<span style="color: #008080; font-style: italic;">' NAME: Java Runtime Environment Installation</span>
<span style="color: #008080; font-style: italic;">' AUTHOR: Andrew J Healey</span>
<span style="color: #008080; font-style: italic;">' DATE  : 2010.07.15</span>
<span style="color: #008080; font-style: italic;">' COMMENT: This script will install the jre references based on processor, existing </span>
<span style="color: #008080; font-style: italic;">' 				   installations, and operating system.  This script is to be run at startup</span>
<span style="color: #008080; font-style: italic;">'				   under the Local System account. No user interaction is required for </span>
<span style="color: #008080; font-style: italic;">'				   this script to work properly.</span>
<span style="color: #008080; font-style: italic;">'======================================================</span>
&nbsp;
<span style="color: #FF8000;">Option</span> Explicit
&nbsp;
<span style="color: #0600FF;">If</span> isClientOperatingSystem <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span> wscript.<span style="color: #0000FF;">quit</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> jreVerMajor, jreVerMinor
<span style="color: #0600FF;">Dim</span> strCommand, strPathToInstall, strInstallFile, strArguments
&nbsp;
<span style="color: #008080; font-style: italic;">'============== BEGIN CONFIGURATION SECTION =================</span>
jreVerMajor <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;jre1.5.0_&quot;</span> <span style="color: #008080; font-style: italic;">'As string</span>
jreVerMinor <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span> <span style="color: #008080; font-style: italic;">'As Integer for &lt;&gt; operations</span>
strPathToInstall <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;\\servername\Software\Java\&quot;</span> <span style="color: #008080; font-style: italic;">'Point to share \\servername\share\folder\</span>
strInstallFile <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;jre-1_5_0_09-windows-i586-p.exe&quot;</span>
strArguments <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;/s /v /qn ADDLOCAL=jrecore,extra IEXPLORER=1 REBOOT=Suppress JAVAUPDATE=0 SYSTRAY=0 WEBSTARTICON=0&quot;</span>
strCommand <span style="color: #008000;">=</span> strPathToInstall <span style="color: #008000;">&amp;</span> strInstallFile <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot; &quot;</span> <span style="color: #008000;">&amp;</span> strArguments
<span style="color: #008080; font-style: italic;">'============== END CONFIGURATION SECTION =================</span>
&nbsp;
<span style="color: #0600FF;">If</span> checkForJRE<span style="color: #000000;">&#40;</span>jreVerMajor, jreVerMinor<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span>
	<span style="color: #0600FF;">Call</span> InstallJava<span style="color: #000000;">&#40;</span>strCommand<span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> checkForJRE<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> jreVerMajor, <span style="color: #FF8000;">ByVal</span> jreVerMinor<span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">Dim</span> jrePath
	<span style="color: #0600FF;">Dim</span> blnMajorFound : blnMajorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
	<span style="color: #0600FF;">Dim</span> blnMinorFound : blnMinorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
&nbsp;
	<span style="color: #0600FF;">If</span> is32bit <span style="color: #FF8000;">Then</span>
		jrePath <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;C:\Program Files\Java\&quot;</span>
	<span style="color: #FF8000;">Else</span>
		jrePath <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;C:\Program Files (x86)\Java\&quot;</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #0600FF;">Dim</span> objFSO : <span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">Dim</span> objFolder : <span style="color: #FF8000;">Set</span> objFolder <span style="color: #008000;">=</span> objFSO.<span style="color: #0000FF;">GetFolder</span><span style="color: #000000;">&#40;</span>jrePath<span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">Dim</span> colSubfolders : <span style="color: #FF8000;">Set</span> colSubfolders <span style="color: #008000;">=</span> objFolder.<span style="color: #0000FF;">Subfolders</span>
		<span style="color: #0600FF;">Dim</span> objSubfolder
&nbsp;
		<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objSubfolder in colSubfolders
			<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">Left</span><span style="color: #000000;">&#40;</span>objSubfolder.<span style="color: #0000FF;">Name</span>,<span style="color: #FF8000;">Len</span><span style="color: #000000;">&#40;</span>jreVerMajor<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> jreVerMajor <span style="color: #FF8000;">Then</span>
				blnMajorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
				<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Right</span><span style="color: #000000;">&#40;</span>objSubfolder.<span style="color: #0000FF;">Name</span>,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> &gt;<span style="color: #008000;">=</span> jreVerMinor <span style="color: #FF8000;">Then</span>
					blnMinorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
				<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
			<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
		<span style="color: #FF8000;">Next</span>
&nbsp;
		<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
			chechForJRE <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
			<span style="color: #0600FF;">Exit</span> <span style="color: #0600FF;">Function</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
		<span style="color: #0600FF;">If</span> blnMajorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #804040;">And</span> blnMinorFound <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span>
			checkForJRE <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
		<span style="color: #FF8000;">Else</span>
			checkForJRE <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
&nbsp;
	<span style="color: #FF8000;">Set</span> objSubfolder <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">Set</span> colSubfolders <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">Set</span> objFolder <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	jrePath <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
	blnMajorFound <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
	blnMinorFound <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
	jreVerMajor <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
	jreVerMinor <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span> 
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> is32bit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Get processor architecture; do not use remotely</span>
	<span style="color: #0600FF;">const</span> HKEY_LOCAL_MACHINE <span style="color: #008000;">=</span> <span style="color: #008000;">&amp;</span>H80000002
	<span style="color: #0600FF;">Dim</span> oReg,strKeyPath,strValueName
	<span style="color: #0600FF;">Dim</span> strValue
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #FF8000;">Set</span> oReg<span style="color: #008000;">=</span>GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
		strKeyPath <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;</span>
		strValueName <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;PROCESSOR_ARCHITECTURE&quot;</span>
		oReg.<span style="color: #0000FF;">GetStringValue</span> HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
&nbsp;
		<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> &lt;&gt; <span style="color: #FF0000;">0</span> or strValue <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;x86&quot;</span> <span style="color: #FF8000;">Then</span>
			is32bit <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
		<span style="color: #FF8000;">Else</span>
			is32bit <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
		<span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Clear</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
&nbsp;
	<span style="color: #FF8000;">Set</span> oReg <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	strKeyPath <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
	strValueName <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span> 
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> InstallJava<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strCommand<span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #0600FF;">Dim</span> objWshShell, intRC
&nbsp;
		<span style="color: #FF8000;">Set</span> objWshShell <span style="color: #008000;">=</span> WScript.<span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;WScript.Shell&quot;</span><span style="color: #000000;">&#41;</span>
		intRC <span style="color: #008000;">=</span> objWshShell.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span>strCommand, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #0600FF;">If</span> intRC &lt;&gt; <span style="color: #FF0000;">0</span> Or <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
			InstallJava <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Failed&quot;</span>
		<span style="color: #FF8000;">Else</span>
			InstallJava <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Success&quot;</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
	<span style="color: #FF8000;">Set</span> objWshShell <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	intRC <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span> 
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> isClientOperatingSystem<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">Dim</span> objWMIService, objItem, colItems
	<span style="color: #0600FF;">Dim</span> strOS
&nbsp;
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #008080; font-style: italic;">' WMI Connection to the object in the CIM namespace</span>
		<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:\\.\root\cimv2&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">' WMI Query to the Win32_OperatingSystem</span>
		<span style="color: #FF8000;">Set</span> colItems <span style="color: #008000;">=</span> objWMIService.<span style="color: #0000FF;">ExecQuery</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Select * from Win32_OperatingSystem&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">' For Each... In Loop (Next at the very end)</span>
		<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objItem in colItems
			strOS <span style="color: #008000;">=</span> objItem.<span style="color: #0000FF;">Caption</span>
		<span style="color: #FF8000;">Next</span>
&nbsp;
		<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strOS,<span style="color: #808080;">&quot;Windows 7&quot;</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> Or <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strOS,<span style="color: #808080;">&quot;XP&quot;</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> Or <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strOS,<span style="color: #808080;">&quot;2000 Professional&quot;</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> Or <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strOS,<span style="color: #808080;">&quot;Vista&quot;</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
			isClientOperatingSystem <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
		<span style="color: #FF8000;">Else</span>
			isClientOperatingSystem <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
		<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span> isClientOperatingSystem <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
&nbsp;
		strOS <span style="color: #008000;">=</span> <span style="color: #FF8000;">Empty</span>
		<span style="color: #FF8000;">Set</span> objItem <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
		<span style="color: #FF8000;">Set</span> colItems <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
		<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;t=Installing+Java+via+Script+and+Group+Policy" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;title=Installing+Java+via+Script+and+Group+Policy&amp;summary=Due%20to%20some%20software%20requirements%2C%20there%20was%20a%20need%20to%20get%20JRE%201.5.0_09%20rolled%20out%20across%20our%20enterprise.%20%20The%20requirements%20were%20pretty%20straight%20forward%3A%0D%0A%0D%0A%09Only%20install%20on%20client%20operating%20systems%20%28Windows%202000%2C%20Windows%20XP%2C%20Windows%20Vista%20and%20Windows%207%29%0D%0A%09Detect%20the%20versions%20of%20Java%20installed.%20If%201&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Installing+Java+via+Script+and+Group+Policy+-+http://b2l.me/aa437s&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Installing+Java+via+Script+and+Group+Policy&amp;du=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;cn=Due%20to%20some%20software%20requirements%2C%20there%20was%20a%20need%20to%20get%20JRE%201.5.0_09%20rolled%20out%20across%20our%20enterprise.%20%20The%20requirements%20were%20pretty%20straight%20forward%3A%0D%0A%0D%0A%09Only%20install%20on%20client%20operating%20systems%20%28Windows%202000%2C%20Windows%20XP%2C%20Windows%20Vista%20and%20Windows%207%29%0D%0A%09Detect%20the%20versions%20of%20Java%20installed.%20If%201" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;title=Installing+Java+via+Script+and+Group+Policy" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;submitHeadline=Installing+Java+via+Script+and+Group+Policy&amp;submitSummary=Due%20to%20some%20software%20requirements%2C%20there%20was%20a%20need%20to%20get%20JRE%201.5.0_09%20rolled%20out%20across%20our%20enterprise.%20%20The%20requirements%20were%20pretty%20straight%20forward%3A%0D%0A%0D%0A%09Only%20install%20on%20client%20operating%20systems%20%28Windows%202000%2C%20Windows%20XP%2C%20Windows%20Vista%20and%20Windows%207%29%0D%0A%09Detect%20the%20versions%20of%20Java%20installed.%20If%201&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/installing-java-via-script-and-group-policy/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/installing-java-via-script-and-group-policy/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Installing%20Java%20via%20Script%20and%20Group%20Policy%22&amp;body=Link: http://halfloaded.com/blog/installing-java-via-script-and-group-policy/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Due%20to%20some%20software%20requirements%2C%20there%20was%20a%20need%20to%20get%20JRE%201.5.0_09%20rolled%20out%20across%20our%20enterprise.%20%20The%20requirements%20were%20pretty%20straight%20forward%3A%0D%0A%0D%0A%09Only%20install%20on%20client%20operating%20systems%20%28Windows%202000%2C%20Windows%20XP%2C%20Windows%20Vista%20and%20Windows%207%29%0D%0A%09Detect%20the%20versions%20of%20Java%20installed.%20If%201" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/installing-java-via-script-and-group-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Part 1: Blocking Bad Hosts &#8211; Finding Them, Easily</title>
		<link>http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/</link>
		<comments>http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 07:19:13 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[event log]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vbScript]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://halfloaded.com/?p=335</guid>
		<description><![CDATA[Download Script: get-bad-hosts.zip While troubleshooting some issues on an OWA Front-End server, I went over to the security log to see if the authentication attempts were getting past this box. The problem I found was the log was so full of failed logon attempts it was difficult to filter out what I was looking for. [...]]]></description>
			<content:encoded><![CDATA[<p>Download Script: <a href="http://halfloaded.com/wp-content/uploads/2009/12/get-bad-hosts.zip">get-bad-hosts.zip</a></p>
<p>While troubleshooting some issues on an OWA Front-End server, I went over to the security log to see if the authentication attempts were getting past this box.  The problem I found was the log was so full of failed logon attempts it was difficult to filter out what I was looking for.  In a twelve hour period, there were thousands of 529 events in the security log.  Now, I know this is nothing new, but I found a few patterns.  I manually exported the log to a CSV, parsed out all the source ip addresses and opened it up in Excel.  What I found was that 98.7% of failed logon attempts were made by just four different ip addresses.  (I recommend using <a href="http://www.maxmind.com/app/locate_ip" target="_blank">MaxMind&#8217;s GeoIP Address Locator</a> for help in determining where the source addresses are located.)<span id="more-335"></span></p>
<p>The easy fix is to setup an IPSec policy to block all traffic coming from those addresses.  And I did just that.  There are many different methods to blocking bad hosts.  And, anybody who has dealt with this knows, they will come back.  Just from different addresses.</p>
<p>One other piece I was able to get from this is that there are several of our users whom have fat fingered their passwords within ActiveSync (or they just have it setup wrong).  And then there are those users who have forgotten their domain, e-mail address, username, etc.</p>
<p>This is step one in my project to automate the blocking of bad hosts.  My goal is to build an automated method for blocking hosts with a high percentage of bad logon attempts within <em>n</em> hours.  And, even if I can&#8217;t get it 100% automated, this first whack at it took my bad logon attempts from 800 per hour to 25 per hour; nearly a 97% improvement!  And, a lot less crap to sift through when troubleshooting real issues.</p>
<p>So, my first goal is to automate a method of extracting the data I want from the event log.  (The script can be found below.)  The most important piece of data is the source ip address.  However, the other pieces of data I decided to extract could be helpful in determining the legitimacy of the logon failure.</p>
<p>To get the data, simply download the script and run &#8220;cscript /nologo get-bad-hosts.vbs &gt; bad-hosts.csv&#8221; (w/o the quotes).  You can then open the file in Excel, do a quick pivot-table and identify the source addresses with the most hits.  At that point, you can add the host (or address block) to an ipsec policy to block all traffic from that address.</p>
<p>In my next post, I&#8217;ll explain the details in setting up a quick ipsec policy to block the bad guys.  Cheers!</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'==========================================================================</span>
<span style="color: #008080; font-style: italic;">' VBScript Source File</span>
<span style="color: #008080; font-style: italic;">' NAME: get-bad-hosts.vbs</span>
<span style="color: #008080; font-style: italic;">' AUTHOR: Andrew J Healey</span>
<span style="color: #008080; font-style: italic;">' WEB: http://halfloaded.com/</span>
<span style="color: #008080; font-style: italic;">' DATE  : Dec 21 2009</span>
<span style="color: #008080; font-style: italic;">' COMMENT: This script will return data in csv format for use in determining</span>
<span style="color: #008080; font-style: italic;">'	hack, lockout or bad logon attempts</span>
<span style="color: #008080; font-style: italic;">' PROCESS: 1) query event log for event id 529; 2) parse data to return</span>
<span style="color: #008080; font-style: italic;">'	useful data; 3) output to screen</span>
<span style="color: #008080; font-style: italic;">' USAGE: cscript /nologo get-bad-hosts.vbs c:\bad-hosts.csv</span>
<span style="color: #008080; font-style: italic;">'==========================================================================</span>
&nbsp;
<span style="color: #FF8000;">Option</span> Explicit
<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> strComputer, objWMIService, colLoggedEvents
<span style="color: #0600FF;">Dim</span> objEvent, objRegEx, colMatches, strMatch
<span style="color: #0600FF;">Dim</span> strUserName, strWorkstation, strIPAddress, strDomain
&nbsp;
<span style="color: #008080; font-style: italic;">'Change to name of computer to query remote machine</span>
strComputer <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;.&quot;</span>
<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:&quot;</span> _
    <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;{impersonationLevel=impersonate}!\\&quot;</span> <span style="color: #008000;">&amp;</span>amp; strComputer <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;\root\cimv2&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Event 529 in the security log are &quot;Failure Audit&quot; for a &quot;Logon/Logoff&quot;</span>
<span style="color: #FF8000;">Set</span> colLoggedEvents <span style="color: #008000;">=</span> objWMIService.<span style="color: #0000FF;">ExecQuery</span> _
        <span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Select * from Win32_NTLogEvent Where Logfile = 'Security' and &quot;</span> _
            <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;EventCode = '529'&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Write header to screen</span>
wscript.<span style="color: #0000FF;">echo</span> <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;User Name&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
			 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Workstation&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
			 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Source IP&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
			 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Windows Domain&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
			 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Date/Time&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Loop through all events matching criteria above: 529 in sec log</span>
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objEvent in colLoggedEvents
	<span style="color: #008080; font-style: italic;">'Use regex to parse any ip addresses from event</span>
	<span style="color: #008080; font-style: italic;">' if no address found, goto next record</span>
	<span style="color: #FF8000;">Set</span> objRegEx <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;VBScript.RegExp&quot;</span><span style="color: #000000;">&#41;</span>
	objRegEx.<span style="color: #0000FF;">Global</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
	objRegEx.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Will return the line of the user name that was used</span>
	objRegEx.<span style="color: #0000FF;">Pattern</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;(\tUser Name:.*\n)&quot;</span>
	<span style="color: #FF8000;">Set</span> colMatches <span style="color: #008000;">=</span> objRegEx.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>objEvent.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> strMatch in colMatches
	   strUserName <span style="color: #008000;">=</span> strMatch.<span style="color: #0000FF;">Value</span>
	<span style="color: #FF8000;">Next</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Will return the line of the workstation name that was used</span>
	objRegEx.<span style="color: #0000FF;">Pattern</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;(\tWorkstation Name:.*\n)&quot;</span>
	<span style="color: #FF8000;">Set</span> colMatches <span style="color: #008000;">=</span> objRegEx.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>objEvent.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> strMatch in colMatches
	   strWorkstation <span style="color: #008000;">=</span> strMatch.<span style="color: #0000FF;">Value</span>
	<span style="color: #FF8000;">Next</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Will return the line of the source ip address</span>
	objRegEx.<span style="color: #0000FF;">Pattern</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;(\tSource Network Address:.*\n)&quot;</span>
	<span style="color: #FF8000;">Set</span> colMatches <span style="color: #008000;">=</span> objRegEx.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>objEvent.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> strMatch in colMatches
	   strIPAddress <span style="color: #008000;">=</span> strMatch.<span style="color: #0000FF;">Value</span>
	<span style="color: #FF8000;">Next</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Will return the line of the domain that was used</span>
	objRegEx.<span style="color: #0000FF;">Pattern</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;\tDomain:(.*\n)&quot;</span>
	<span style="color: #FF8000;">Set</span> colMatches <span style="color: #008000;">=</span> objRegEx.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>objEvent.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> strMatch in colMatches
	   strDomain <span style="color: #008000;">=</span> strMatch.<span style="color: #0000FF;">Value</span>
	<span style="color: #FF8000;">Next</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Output clean csv line for easy reading in spreadsheet program</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; GetCleanText<span style="color: #000000;">&#40;</span>strUserName<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
				 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; GetCleanText<span style="color: #000000;">&#40;</span>strWorkstation<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
				 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; GetCleanText<span style="color: #000000;">&#40;</span>strIpAddress<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
				 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; GetCleanText<span style="color: #000000;">&#40;</span>strDomain<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;,&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
				 <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; WMIDateStringToDate<span style="color: #000000;">&#40;</span>objEvent.<span style="color: #0000FF;">TimeWritten</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">chr</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">34</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Next</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> GetCleanText<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">byVal</span> strText<span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'This will cleanup the text and return only necessary data</span>
	<span style="color: #008080; font-style: italic;">' I'm sure there is a better way to do this :)</span>
	<span style="color: #0600FF;">dim</span> tmp,txt
	tmp <span style="color: #008000;">=</span> <span style="color: #0600FF;">Split</span><span style="color: #000000;">&#40;</span>strText,<span style="color: #808080;">&quot;:&quot;</span><span style="color: #000000;">&#41;</span>
	txt <span style="color: #008000;">=</span> tmp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
	txt <span style="color: #008000;">=</span> <span style="color: #0600FF;">Replace</span><span style="color: #000000;">&#40;</span>txt,vbTab,<span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
	txt <span style="color: #008000;">=</span> <span style="color: #0600FF;">Replace</span><span style="color: #000000;">&#40;</span>txt,vbCrLf,<span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
	txt <span style="color: #008000;">=</span> <span style="color: #0600FF;">Trim</span><span style="color: #000000;">&#40;</span>txt<span style="color: #000000;">&#41;</span>
	GetCleanText <span style="color: #008000;">=</span> txt
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> WMIDateStringToDate<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">byVal</span> dtmEventDate<span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Borrowed from the &quot;Hey, Scripting Guy! BLOG&quot;</span>
	<span style="color: #008080; font-style: italic;">' --&amp;gt; Search: WMIDateStringToDate</span>
    WMIDateStringToDate <span style="color: #008000;">=</span> <span style="color: #0600FF;">CDate</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>dtmEventDate, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;/&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
        <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>dtmEventDate, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;/&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">Left</span><span style="color: #000000;">&#40;</span>dtmEventDate, <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> _
            <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot; &quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #FF8000;">Mid</span> <span style="color: #000000;">&#40;</span>dtmEventDate, <span style="color: #FF0000;">9</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;:&quot;</span> <span style="color: #008000;">&amp;</span>amp; _
                <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>dtmEventDate, <span style="color: #FF0000;">11</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;:&quot;</span> <span style="color: #008000;">&amp;</span>amp; <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>dtmEventDate, _
                    <span style="color: #FF0000;">13</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;t=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;title=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily&amp;summary=Download%20Script%3A%20get-bad-hosts.zip%0D%0A%0D%0AWhile%20troubleshooting%20some%20issues%20on%20an%20OWA%20Front-End%20server%2C%20I%20went%20over%20to%20the%20security%20log%20to%20see%20if%20the%20authentication%20attempts%20were%20getting%20past%20this%20box.%20%20The%20problem%20I%20found%20was%20the%20log%20was%20so%20full%20of%20failed%20logon%20attempts%20it%20was%20difficult%20to%20filter%20out%20w&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily+-+http://b2l.me/b4ge9&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily&amp;du=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;cn=Download%20Script%3A%20get-bad-hosts.zip%0D%0A%0D%0AWhile%20troubleshooting%20some%20issues%20on%20an%20OWA%20Front-End%20server%2C%20I%20went%20over%20to%20the%20security%20log%20to%20see%20if%20the%20authentication%20attempts%20were%20getting%20past%20this%20box.%20%20The%20problem%20I%20found%20was%20the%20log%20was%20so%20full%20of%20failed%20logon%20attempts%20it%20was%20difficult%20to%20filter%20out%20w" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;title=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;submitHeadline=Part+1%3A+Blocking+Bad+Hosts+-+Finding+Them%2C+Easily&amp;submitSummary=Download%20Script%3A%20get-bad-hosts.zip%0D%0A%0D%0AWhile%20troubleshooting%20some%20issues%20on%20an%20OWA%20Front-End%20server%2C%20I%20went%20over%20to%20the%20security%20log%20to%20see%20if%20the%20authentication%20attempts%20were%20getting%20past%20this%20box.%20%20The%20problem%20I%20found%20was%20the%20log%20was%20so%20full%20of%20failed%20logon%20attempts%20it%20was%20difficult%20to%20filter%20out%20w&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Part%201%3A%20Blocking%20Bad%20Hosts%20-%20Finding%20Them%2C%20Easily%22&amp;body=Link: http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Download%20Script%3A%20get-bad-hosts.zip%0D%0A%0D%0AWhile%20troubleshooting%20some%20issues%20on%20an%20OWA%20Front-End%20server%2C%20I%20went%20over%20to%20the%20security%20log%20to%20see%20if%20the%20authentication%20attempts%20were%20getting%20past%20this%20box.%20%20The%20problem%20I%20found%20was%20the%20log%20was%20so%20full%20of%20failed%20logon%20attempts%20it%20was%20difficult%20to%20filter%20out%20w" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/part-1-blocking-bad-hosts-finding-them-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logon Script: Move Local PST Files To Network Share</title>
		<link>http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/</link>
		<comments>http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 03:25:05 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[logon script]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[pst]]></category>
		<category><![CDATA[vbScript]]></category>

		<guid isPermaLink="false">http://halfloaded.com/?p=322</guid>
		<description><![CDATA[Download Script: move-pst-to-network.zip So, my buddy (and former co-worker) called me yesterday for some help with a script he put together.  His script checked the local profile in Outlook for any PST files that were stored locally.  If it found any, it would them move them to the users home space.  We tried and tried [...]]]></description>
			<content:encoded><![CDATA[<p>Download Script: <a href="http://halfloaded.com/wp-content/uploads/2009/10/move-pst-to-network.zip">move-pst-to-network.zip</a></p>
<p>So, my buddy (and former co-worker) called me yesterday for some help with a script he put together.  His script checked the local profile in Outlook for any PST files that were stored locally.  If it found any, it would them move them to the users home space.  We tried and tried to get the script to work properly but it never seemed to work 100%.  Being that he is a good friend and this would be useful at work, I decided to take the work he had put in and get the thing working.<span id="more-322"></span></p>
<p>Here is what the script does:</p>
<ol>
<li>Checks to see if the computer is a laptop.  If it is, the user probably uses Outlook offline and/or over VPN so moving the PST to a network share will be detrimental to the user&#8217;s experience.  If you don&#8217;t care, just comment out lines 17-21.</li>
<li>Checks to see if Outlook is installed and can be launched properly.  If it can not, no sense in continuing the script.  It will exit.</li>
<li>Checks to see that the target (network) directory exists and is writable.  If it does not exist or is not writable, the script will exit.</li>
<li>Enumerates all the local stores and returns all the PST files.</li>
<li>Check to see if the PST files are stored on local drives.  It will exclude drives that are mapped network drives and/or removable media.</li>
<li>Check if a file already exists in the target directory with the same name.  If one does, it will not copy the file over. (I may update the script to move and rename the file to ensure all local PSTs are moved.</li>
<li>Removes all Personal Folders from Outlook that matched criteria.</li>
<li>Moves actual PST files to network share (Outlook will close to release the file lock on the PST file).</li>
<li>Adds all the Personal Folders back to Outlook.</li>
</ol>
<p>I have tested this on Windows XP w/ Office 2007 and Office 2003.  I am interested in hearing if this works or not in your environment.  I hope you find this useful.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'==========================================================================</span>
<span style="color: #008080; font-style: italic;">' VBScript Source File</span>
<span style="color: #008080; font-style: italic;">' NAME: move-pst-to-network</span>
<span style="color: #008080; font-style: italic;">' AUTHOR: Andrew J Healey &amp;amp; Nate Stevenson</span>
<span style="color: #008080; font-style: italic;">' WEB: http://halfloaded.com/</span>
<span style="color: #008080; font-style: italic;">' DATE  : 2010.14.2009</span>
<span style="color: #008080; font-style: italic;">' COMMENT: This script will move any mapped PST files that are located on</span>
<span style="color: #008080; font-style: italic;">'	local disks to a network share.</span>
<span style="color: #008080; font-style: italic;">' PROCESS: 1) determine if laptop; 2) determine if outlook installed</span>
<span style="color: #008080; font-style: italic;">'	3) determine local drives; 4) check for local pst's; 5) move pst's</span>
<span style="color: #008080; font-style: italic;">'	to network; 6) remap pst files</span>
<span style="color: #008080; font-style: italic;">'==========================================================================</span>
&nbsp;
<span style="color: #FF8000;">Option</span> Explicit
&nbsp;
<span style="color: #008080; font-style: italic;">'Determine if a laptop (remove if you don't care)</span>
<span style="color: #0600FF;">If</span> IsLaptop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span> <span style="color: #FF8000;">Then</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Computer is a laptop or the chassis could not be determined.&quot;</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Exiting.&quot;</span>
	wscript.<span style="color: #0000FF;">quit</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Determine if outlook is installed</span>
<span style="color: #0600FF;">If</span> IsOutlookInstalled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Could not launch Outlook.&quot;</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Exiting.&quot;</span>
	wscript.<span style="color: #0000FF;">quit</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Get user name</span>
<span style="color: #0600FF;">Dim</span> WshNetwork : <span style="color: #FF8000;">Set</span> WshNetwork <span style="color: #008000;">=</span> WScript.<span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;WScript.Network&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> user : user <span style="color: #008000;">=</span> <span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>WshNetwork.<span style="color: #0000FF;">UserName</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> WshNetwork <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> strNetworkPath
<span style="color: #008080; font-style: italic;">'=========================================================================</span>
<span style="color: #008080; font-style: italic;">' Configuration Section</span>
strNetworkPath <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;\\servername\homes\&quot;</span> <span style="color: #008000;">&amp;</span>amp; user <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;\&quot;</span>
<span style="color: #008080; font-style: italic;">' End Configuration Section</span>
<span style="color: #008080; font-style: italic;">'=========================================================================</span>
<span style="color: #008080; font-style: italic;">'Fix network path if forgot to include trailing slash...</span>
<span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #0600FF;">Right</span><span style="color: #000000;">&#40;</span>strNetworkPath,<span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;\&quot;</span> <span style="color: #FF8000;">Then</span> strNetworkPath <span style="color: #008000;">=</span> strNetworkPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;\&quot;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Determine if network path is writable</span>
<span style="color: #0600FF;">If</span> IsPathWritable<span style="color: #000000;">&#40;</span>strNetworkPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Remote path is not writable.&quot;</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Exiting.&quot;</span>
	wscript.<span style="color: #0000FF;">quit</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Instatiate objects</span>
<span style="color: #0600FF;">Dim</span> objOutlook, objNS, objFSO, objFolder
<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Outlook.Application&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> objNS <span style="color: #008000;">=</span> objOutlook.<span style="color: #0000FF;">GetNamespace</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MAPI&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Sort through all stores in outlook and add all local pst</span>
<span style="color: #008080; font-style: italic;">' paths into an array. Then remove the store from outlook.</span>
<span style="color: #0600FF;">Dim</span> pstFiles
<span style="color: #0600FF;">Dim</span> count : count <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>
<span style="color: #0600FF;">Dim</span> arrPaths<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objFolder In objNS.<span style="color: #008000;">Folders</span>
	<span style="color: #0600FF;">If</span> GetPSTPath<span style="color: #000000;">&#40;</span>objFolder.<span style="color: #0000FF;">StoreID</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #808080;">&quot;&quot;</span> <span style="color: #FF8000;">Then</span>
		pstFiles <span style="color: #008000;">=</span> GetPSTPath<span style="color: #000000;">&#40;</span>objFolder.<span style="color: #0000FF;">StoreID</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">If</span> IsStoredLocal<span style="color: #000000;">&#40;</span>pstFiles<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span> <span style="color: #FF8000;">Then</span>
			<span style="color: #0600FF;">If</span> objFSO.<span style="color: #0000FF;">FileExists</span><span style="color: #000000;">&#40;</span>strNetworkPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>pstFiles,<span style="color: #0600FF;">InStrRev</span><span style="color: #000000;">&#40;</span>pstFiles,<span style="color: #808080;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span> <span style="color: #FF8000;">Then</span>
				wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;A pst file already exists with the same name.&quot;</span> <span style="color: #008000;">&amp;</span>amp; vbCrLf <span style="color: #008000;">&amp;</span>amp; _
						vbTab <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Source: &quot;</span> <span style="color: #008000;">&amp;</span>amp; pstPath <span style="color: #008000;">&amp;</span>amp; vbCrLf <span style="color: #008000;">&amp;</span>amp; _
						vbTab <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;Target: &quot;</span> <span style="color: #008000;">&amp;</span>amp; strNetworkPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>pstPath,<span style="color: #0600FF;">InStrRev</span><span style="color: #000000;">&#40;</span>pstPath,<span style="color: #808080;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
			<span style="color: #FF8000;">Else</span>
				count <span style="color: #008000;">=</span> count <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>
				<span style="color: #0600FF;">ReDim</span> Preserve arrPaths<span style="color: #000000;">&#40;</span>count<span style="color: #000000;">&#41;</span>
				arrPaths<span style="color: #000000;">&#40;</span>count<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> pstFiles
				objOutlook.<span style="color: #0000FF;">Session</span>.<span style="color: #0000FF;">RemoveStore</span> objFolder
			<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #FF8000;">Next</span>
&nbsp;
objOutlook.<span style="color: #0000FF;">Session</span>.<span style="color: #0000FF;">Logoff</span>
objOutlook.<span style="color: #0000FF;">Quit</span>
<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
<span style="color: #FF8000;">Set</span> objNS <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
&nbsp;
<span style="color: #0600FF;">if</span> count <span style="color: #008000;">&amp;</span>lt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">then</span>
	wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;No local PST Files Found.&quot;</span>
	wscript.<span style="color: #0000FF;">quit</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'If local PST files were found, move them to the new location</span>
<span style="color: #008080; font-style: italic;">' Echo output if the file already exists</span>
<span style="color: #0600FF;">Dim</span> pstPath
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> pstPath in arrPaths
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		objFSO.<span style="color: #0000FF;">MoveFile</span> pstPath, strNetworkPath
		<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
			wscript.<span style="color: #0000FF;">sleep</span> <span style="color: #FF0000;">5000</span>
			objFSO.<span style="color: #0000FF;">MoveFile</span> pstPath, strNetworkPath
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Clear</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
<span style="color: #FF8000;">Next</span>
<span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Re-open outlook</span>
<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Outlook.Application&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> objNS <span style="color: #008000;">=</span> objOutlook.<span style="color: #0000FF;">GetNamespace</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;MAPI&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Re-map Outlook folders</span>
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> pstPath in arrPaths
	objNS.<span style="color: #0000FF;">AddStore</span> strNetworkPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>pstPath,<span style="color: #0600FF;">InStrRev</span><span style="color: #000000;">&#40;</span>pstPath,<span style="color: #808080;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Next</span>
&nbsp;
objOutlook.<span style="color: #0000FF;">Session</span>.<span style="color: #0000FF;">Logoff</span>
objOutlook.<span style="color: #0000FF;">Quit</span>
<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
<span style="color: #FF8000;">Set</span> objNS <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Done.&quot;</span>
wscript.<span style="color: #0000FF;">quit</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> GetPSTPath<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">byVal</span> <span style="color: #FF8000;">input</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Will return the path of all PST files</span>
	<span style="color: #008080; font-style: italic;">' Took Function from: http://www.vistax64.com/vb-script/</span>
	<span style="color: #0600FF;">Dim</span> i, strSubString, strPath
	<span style="color: #FF8000;">For</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span> <span style="color: #FF8000;">To</span> <span style="color: #FF8000;">Len</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">input</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Step</span> <span style="color: #FF0000;">2</span>
		strSubString <span style="color: #008000;">=</span> <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">input</span>,i,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> strSubString <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;00&quot;</span> <span style="color: #FF8000;">Then</span>
			strPath <span style="color: #008000;">=</span> strPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #0600FF;">ChrW</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&amp;amp;H&quot;</span> <span style="color: #008000;">&amp;</span>amp; strSubString<span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #FF8000;">Next</span>
&nbsp;
	<span style="color: #0600FF;">Select</span> <span style="color: #0600FF;">Case</span> <span style="color: #0600FF;">True</span>
		<span style="color: #0600FF;">Case</span> <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #808080;">&quot;:\&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span>
			GetPSTPath <span style="color: #008000;">=</span> <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #808080;">&quot;:\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">Case</span> <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #808080;">&quot;\\&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span>
			GetPSTPath <span style="color: #008000;">=</span> <span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>strPath,<span style="color: #808080;">&quot;\\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Select</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> IsLaptop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Determine if the computer is a mobile machine</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #008080; font-style: italic;">'Instantiate objects</span>
		<span style="color: #0600FF;">Dim</span> objWMIService, colChassis, objChassis, strChassisType
		<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #FF8000;">Set</span> colChassis <span style="color: #008000;">=</span> objWMIService.<span style="color: #0000FF;">ExecQuery</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Select * from Win32_SystemEnclosure&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">'Check chassis type</span>
		<span style="color: #008080; font-style: italic;">'http://msdn.microsoft.com/en-us/library/aa394474%28VS.85%29.aspx</span>
		<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objChassis in colChassis
			<span style="color: #FF8000;">For</span>  <span style="color: #0600FF;">Each</span> strChassisType in objChassis.<span style="color: #0000FF;">ChassisTypes</span>
				<span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>strChassisType <span style="color: #008000;">&amp;</span>gt;<span style="color: #008000;">=</span> <span style="color: #FF0000;">8</span> <span style="color: #804040;">And</span> strChassisType <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">=</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span> Or <span style="color: #000000;">&#40;</span>strChassisType <span style="color: #008000;">=</span> <span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
					IsLaptop <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
					<span style="color: #0600FF;">Exit</span> <span style="color: #FF8000;">For</span>
				<span style="color: #FF8000;">Else</span>
					IsLaptop <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
				<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
			<span style="color: #FF8000;">Next</span>
		<span style="color: #FF8000;">Next</span>
	<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span> IsLaptop <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
	<span style="color: #FF8000;">Set</span> colChassis <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	objChassis <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span> 
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> IsOutlookInstalled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Function will return false if unable to launch outlook</span>
	<span style="color: #008080; font-style: italic;">' This adds some overhead but it is ultimately the best</span>
	<span style="color: #008080; font-style: italic;">' way to truly determine if script will function properly.</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Outlook.Application&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
			IsOutlookInstalled <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
			<span style="color: #0600FF;">Exit</span> <span style="color: #0600FF;">Function</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
	IsOutlookInstalled <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
	objOutlook.<span style="color: #0000FF;">Session</span>.<span style="color: #0000FF;">Logoff</span>
	objOutlook.<span style="color: #0000FF;">Quit</span>
	<span style="color: #FF8000;">Set</span> objOutlook <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> IsPathWritable<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">byVal</span> strPath<span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Check to make sure the path is writable. If it is not, no</span>
	<span style="color: #008080; font-style: italic;">' need to continue processing.</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Scripting.FileSystemObject&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">Dim</span> min : min <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>
		<span style="color: #0600FF;">Dim</span> max : max <span style="color: #008000;">=</span> <span style="color: #FF0000;">1000</span>
		<span style="color: #0600FF;">Dim</span> rand : rand <span style="color: #008000;">=</span> <span style="color: #0600FF;">Int</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>max <span style="color: #008000;">-</span> min <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #0600FF;">Rnd</span> <span style="color: #008000;">+</span> min<span style="color: #000000;">&#41;</span>
		<span style="color: #0600FF;">Dim</span> fullFileName : fullFileName <span style="color: #008000;">=</span> strPath <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;temporary-&quot;</span> <span style="color: #008000;">&amp;</span>amp; rand <span style="color: #008000;">&amp;</span>amp; <span style="color: #808080;">&quot;.txt&quot;</span>
		<span style="color: #0600FF;">Dim</span> objFile : <span style="color: #FF8000;">Set</span> objFile <span style="color: #008000;">=</span> objFSO.<span style="color: #0000FF;">CreateTextFile</span><span style="color: #000000;">&#40;</span>fullFileName, <span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span>
		objFile.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Test file creation of &quot;</span> <span style="color: #008000;">&amp;</span>amp; fullFileName<span style="color: #000000;">&#41;</span>
		objFile.<span style="color: #0600FF;">Close</span>
		<span style="color: #0600FF;">If</span> objFSO.<span style="color: #0000FF;">FileExists</span><span style="color: #000000;">&#40;</span>fullFileName<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
			IsPathWritable <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
			objFSO.<span style="color: #0000FF;">DeleteFile</span><span style="color: #000000;">&#40;</span>fullFileName<span style="color: #000000;">&#41;</span>
		<span style="color: #FF8000;">Else</span>
			IsPathWritable <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span> IsPathWritable <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
	<span style="color: #FF8000;">Set</span> objFile <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	<span style="color: #FF8000;">Set</span> objFSO <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
	rand <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
	max <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
	min <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
	fullFileName <span style="color: #008000;">=</span> <span style="color: #FF8000;">Null</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> IsStoredLocal<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> fullFileName<span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Check if the PST is stored locally or on a mapped or removable drive</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> <span style="color: #FF8000;">Resume</span> <span style="color: #FF8000;">Next</span>
		<span style="color: #0600FF;">Dim</span> objDisk, objWMIService, colDisks
		<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #FF8000;">Set</span> colDisks <span style="color: #008000;">=</span> objWMIService.<span style="color: #0000FF;">ExecQuery</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SELECT * FROM Win32_LogicalDisk&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objDisk in colDisks
			<span style="color: #0600FF;">If</span> objDisk.<span style="color: #0000FF;">DriveType</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span> <span style="color: #FF8000;">Then</span>
				<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span>fullFileName,objDisk.<span style="color: #0000FF;">DeviceID</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
					IsStoredLocal <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
					<span style="color: #0600FF;">Exit</span> <span style="color: #FF8000;">For</span>
				<span style="color: #FF8000;">Else</span>
					IsStoredLocal <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
				<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
			<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
		<span style="color: #FF8000;">Next</span>
	<span style="color: #0600FF;">If</span> <span style="color: #008000;">Err</span>.<span style="color: #0000FF;">Number</span> <span style="color: #008000;">&amp;</span>lt;<span style="color: #008000;">&amp;</span>gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span> IsLocalDrive <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
	<span style="color: #FF8000;">On</span> <span style="color: #FF8000;">Error</span> GoTo <span style="color: #FF0000;">0</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;t=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;title=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share&amp;summary=Download%20Script%3A%20move-pst-to-network.zip%0D%0A%0D%0ASo%2C%20my%20buddy%20%28and%20former%20co-worker%29%20called%20me%20yesterday%20for%20some%20help%20with%20a%20script%20he%20put%20together.%C2%A0%20His%20script%20checked%20the%20local%20profile%20in%20Outlook%20for%20any%20PST%20files%20that%20were%20stored%20locally.%C2%A0%20If%20it%20found%20any%2C%20it%20would%20them%20move%20them%20to%20the%20users%20home%20&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share+-+http://b2l.me/b4gey&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share&amp;du=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;cn=Download%20Script%3A%20move-pst-to-network.zip%0D%0A%0D%0ASo%2C%20my%20buddy%20%28and%20former%20co-worker%29%20called%20me%20yesterday%20for%20some%20help%20with%20a%20script%20he%20put%20together.%C2%A0%20His%20script%20checked%20the%20local%20profile%20in%20Outlook%20for%20any%20PST%20files%20that%20were%20stored%20locally.%C2%A0%20If%20it%20found%20any%2C%20it%20would%20them%20move%20them%20to%20the%20users%20home%20" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;title=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;submitHeadline=Logon+Script%3A+Move+Local+PST+Files+To+Network+Share&amp;submitSummary=Download%20Script%3A%20move-pst-to-network.zip%0D%0A%0D%0ASo%2C%20my%20buddy%20%28and%20former%20co-worker%29%20called%20me%20yesterday%20for%20some%20help%20with%20a%20script%20he%20put%20together.%C2%A0%20His%20script%20checked%20the%20local%20profile%20in%20Outlook%20for%20any%20PST%20files%20that%20were%20stored%20locally.%C2%A0%20If%20it%20found%20any%2C%20it%20would%20them%20move%20them%20to%20the%20users%20home%20&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Logon%20Script%3A%20Move%20Local%20PST%20Files%20To%20Network%20Share%22&amp;body=Link: http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Download%20Script%3A%20move-pst-to-network.zip%0D%0A%0D%0ASo%2C%20my%20buddy%20%28and%20former%20co-worker%29%20called%20me%20yesterday%20for%20some%20help%20with%20a%20script%20he%20put%20together.%C2%A0%20His%20script%20checked%20the%20local%20profile%20in%20Outlook%20for%20any%20PST%20files%20that%20were%20stored%20locally.%C2%A0%20If%20it%20found%20any%2C%20it%20would%20them%20move%20them%20to%20the%20users%20home%20" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/logon-script-move-local-pst-files-to-network-share/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>vbScript &#8211; List All Members Of Sensitive Groups: Schema, Enterprise and Domain Admins</title>
		<link>http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/</link>
		<comments>http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 19:24:46 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[vbScript]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://halfloaded.com/?p=247</guid>
		<description><![CDATA[Update 2009.04.16: At the request of a commenter, I added a couple lines to the script that will dump the output to a text file in the root of the C: drive. I also corrected a couple errors in the script. I was tasked to get a dump of all the users in our Schema [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update <em>2009.04.16</em></strong>: At the request of a commenter, I added a couple lines to the script that will dump the output to a text file in the root of the C: drive.  I also corrected a couple errors in the script.</p>
<p>I was tasked to get a dump of all the users in our Schema Admins, Enterprise Admins and Domain Admins for our Forest.  I started thinking about it and realized a couple things.  Two of the three groups reside at the forest root while the Domain Admins group exists for every domain in the forest.  This meant I would need to enumerate every domain and depending on the domain, enumerate either all three groups or just one.<span id="more-247"></span></p>
<p>My thinking was overly complex and I realized this halfway through writing a new script.  Using the power of LDAP, I can use a logical &#8220;or&#8221; (|) statement.  When run against a domain, it would always return &#8220;Domain Admins&#8221; since it will always exist in an AD domain.  When it is run against the forest root domain, it would also return the &#8220;Enterprise Admins&#8221; group and &#8220;Schema Admins&#8221; group.  Here is the LDAP query:</p>
<p><code>(&amp;(objectCategory=group)(|((name=Enterprise Admins*)(name=Domain Admins*)(name=Schema Admins*))))</code></p>
<p>At this point, all I need to do is this:</p>
<ol>
<li>Enumerate all domains in the forest</li>
<li>Loop through each domain</li>
<li>Execute LDAP query against each domain</li>
<li>Loop through LDAP query results</li>
<li>Dump membership of each group</li>
</ol>
<p>The script below does just that.  I hope some find it useful.  There is no configuration necessary.  You should be able to just run it from your environment as no domain references (or really anything) is hard coded.  The only thing you may want to add to or remove from is the LDAP filter.  Cheers!</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'==========================================================================
</span><span style="color: #008000;">' VBScript Source File
</span><span style="color: #008000;">' NAME: Active Directory Admin Audit
</span><span style="color: #008000;">' AUTHOR: Andrew J Healey
</span><span style="color: #008000;">' DATE  : 2009.04.16
</span><span style="color: #008000;">' COMMENT: This script will check all the domains within a forest
</span><span style="color: #008000;">'		and report all the members of the following groups: Schema
</span><span style="color: #008000;">'		Admins, Enterprise Admins and Domain Admins. See notes to
</span><span style="color: #008000;">'		expand on the groups.
</span><span style="color: #008000;">'==========================================================================
</span>
<span style="color: #008000;">'Define Constants
</span><span style="color: #000080;">Const</span> adUseClient = 3
<span style="color: #000080;">Const</span> ForWriting = 2
&nbsp;
<span style="color: #008000;">'Set the path and filename for the dump of sensitive users
</span><span style="color: #008000;">'  Folder must exist!
</span>fileTemp = <span style="color: #800000;">&quot;C:\AD Admin Audit.txt&quot;</span>
&nbsp;
<span style="color: #008000;">'Create tmp file and report file
</span><span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
<span style="color: #000080;">Set</span> objTempFile = objFSO.OpenTextFile(fileTemp, ForWriting, <span style="color: #000080;">True</span>)
&nbsp;
<span style="color: #008000;">'Query RootDSE and return array with all AD domains in forest
</span><span style="color: #000080;">Set</span> adoComm = CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
<span style="color: #000080;">Set</span> adoConn = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
adoConn.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
adoConn.cursorLocation = adUseClient
adoConn.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Provider&quot;</span>
adoComm.ActiveConnection = adoConn
&nbsp;
<span style="color: #000080;">Set</span> objRootDSE = GetObject(<span style="color: #800000;">&quot;LDAP://RootDSE&quot;</span>)
strBase   =  <span style="color: #800000;">&quot;&lt;GC://&quot;</span> &amp; objRootDSE.<span style="color: #000080;">Get</span>(<span style="color: #800000;">&quot;rootDomainNamingContext&quot;</span>) &amp; <span style="color: #800000;">&quot;&gt;;&quot;</span>
strFilter = <span style="color: #800000;">&quot;(objectcategory=domainDNS);&quot;</span>
strAttrs  = <span style="color: #800000;">&quot;distinguishedName;&quot;</span>
strScope  = <span style="color: #800000;">&quot;subtree&quot;</span>
&nbsp;
strQuery = strBase &amp;amp; strFilter &amp;amp; strAttrs &amp;amp; strScope
adoComm.CommandText = strQuery
adoComm.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 50
adoComm.Properties(<span style="color: #800000;">&quot;Timeout&quot;</span>) = 30
adoComm.Properties(<span style="color: #800000;">&quot;Cache Results&quot;</span>) = <span style="color: #000080;">False</span>
&nbsp;
<span style="color: #000080;">Set</span> adoRS = adoComm.Execute
&nbsp;
<span style="color: #008000;">'Start Loop
</span><span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> adoRS.EOF
	<span style="color: #008000;">'Parse ad search results to create well formed DNS domain
</span>	strDomain = Replace(adoRS.Fields(0).Value,<span style="color: #800000;">&quot;DC=&quot;</span>,<span style="color: #800000;">&quot;&quot;</span>)
	strDomain = Replace(strDomain,<span style="color: #800000;">&quot;,&quot;</span>,<span style="color: #800000;">&quot;.&quot;</span>)
	<span style="color: #000080;">Call</span> GrpAll(strDomain)
	adoRS.MoveNext
<span style="color: #000080;">Loop</span>
adoRS.<span style="color: #000080;">Close</span>
adoConn.<span style="color: #000080;">Close</span>
wscript.quit
&nbsp;
<span style="color: #000080;">Function</span> GrpAll(x)
	<span style="color: #008000;">'To search for more groups, edit the &quot;strFilter&quot; line. It uses a simple
</span>	<span style="color: #008000;">' LDAP or (|) so multiple groups can be added. It uses ADO record sets
</span>	<span style="color: #008000;">' to loop so it doesn't have to find all of them, just one. Every domain
</span>	<span style="color: #008000;">' will contain at least the Domain Admins group.
</span>	<span style="color: #000080;">Set</span> adoCommand = CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
	<span style="color: #000080;">Set</span> adoConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
	adoConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
	adoConnection.cursorLocation = adUseClient
	adoConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Provider&quot;</span>
	adoCommand.ActiveConnection = adoConnection
&nbsp;
	strBase   = <span style="color: #800000;">&quot;;&quot;</span>
	strFilter = <span style="color: #800000;">&quot;(&amp;amp;(objectCategory=group)(|((name=Enterprise Admins*)&quot;</span> &amp;amp; _
				<span style="color: #800000;">&quot;(name=Domain Admins*)(name=Schema Admins*))));&quot;</span>
	strAttrs  = <span style="color: #800000;">&quot;name,member;&quot;</span>
	strScope  = <span style="color: #800000;">&quot;subtree&quot;</span>
&nbsp;
	strQuery = strBase &amp;amp; strFilter &amp;amp; strAttrs &amp;amp; strScope
	adoCommand.CommandText = strQuery
	adoCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 5000
	adoCommand.Properties(<span style="color: #800000;">&quot;Timeout&quot;</span>) = 30
	adoCommand.Properties(<span style="color: #800000;">&quot;Cache Results&quot;</span>) = <span style="color: #000080;">False</span>
&nbsp;
	<span style="color: #000080;">Set</span> adoRecordset = adoCommand.Execute
&nbsp;
	objTempFile.WriteLine <span style="color: #800000;">&quot;Group report for domain: &quot;</span> &amp;amp; x
&nbsp;
	adoRecordset.MoveFirst
&nbsp;
	<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> adoRecordset.EOF
	    objTempFile.WriteLine vbTab &amp;amp; adoRecordset.Fields(0).Value
		<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strMember <span style="color: #000080;">in</span> adoRecordset.Fields(1).Value
			objTempFile.WriteLine vbTab &amp;amp; vbTab &amp;amp; strMember
		<span style="color: #000080;">Next</span>
	    adoRecordset.MoveNext
	<span style="color: #000080;">Loop</span>
&nbsp;
	adoRecordset.<span style="color: #000080;">Close</span>
	adoConnection.<span style="color: #000080;">Close</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;t=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+Admins" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;title=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+Admins&amp;summary=Update%202009.04.16%3A%20At%20the%20request%20of%20a%20commenter%2C%20I%20added%20a%20couple%20lines%20to%20the%20script%20that%20will%20dump%20the%20output%20to%20a%20text%20file%20in%20the%20root%20of%20the%20C%3A%20drive.%20%20I%20also%20corrected%20a%20couple%20errors%20in%20the%20script.%0D%0A%0D%0AI%20was%20tasked%20to%20get%20a%20dump%20of%20all%20the%20users%20in%20our%20Schema%20Admins%2C%20Enterprise%20Admins%20and%20Dom&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+A%5B..%5D+-+http://b2l.me/b4gfd&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+Admins&amp;du=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;cn=Update%202009.04.16%3A%20At%20the%20request%20of%20a%20commenter%2C%20I%20added%20a%20couple%20lines%20to%20the%20script%20that%20will%20dump%20the%20output%20to%20a%20text%20file%20in%20the%20root%20of%20the%20C%3A%20drive.%20%20I%20also%20corrected%20a%20couple%20errors%20in%20the%20script.%0D%0A%0D%0AI%20was%20tasked%20to%20get%20a%20dump%20of%20all%20the%20users%20in%20our%20Schema%20Admins%2C%20Enterprise%20Admins%20and%20Dom" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;title=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+Admins" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;submitHeadline=vbScript+-+List+All+Members+Of+Sensitive+Groups%3A+Schema%2C+Enterprise+and+Domain+Admins&amp;submitSummary=Update%202009.04.16%3A%20At%20the%20request%20of%20a%20commenter%2C%20I%20added%20a%20couple%20lines%20to%20the%20script%20that%20will%20dump%20the%20output%20to%20a%20text%20file%20in%20the%20root%20of%20the%20C%3A%20drive.%20%20I%20also%20corrected%20a%20couple%20errors%20in%20the%20script.%0D%0A%0D%0AI%20was%20tasked%20to%20get%20a%20dump%20of%20all%20the%20users%20in%20our%20Schema%20Admins%2C%20Enterprise%20Admins%20and%20Dom&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22vbScript%20-%20List%20All%20Members%20Of%20Sensitive%20Groups%3A%20Schema%2C%20Enterprise%20and%20Domain%20Admins%22&amp;body=Link: http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Update%202009.04.16%3A%20At%20the%20request%20of%20a%20commenter%2C%20I%20added%20a%20couple%20lines%20to%20the%20script%20that%20will%20dump%20the%20output%20to%20a%20text%20file%20in%20the%20root%20of%20the%20C%3A%20drive.%20%20I%20also%20corrected%20a%20couple%20errors%20in%20the%20script.%0D%0A%0D%0AI%20was%20tasked%20to%20get%20a%20dump%20of%20all%20the%20users%20in%20our%20Schema%20Admins%2C%20Enterprise%20Admins%20and%20Dom" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/vbscript-list-all-members-of-sensitive-groups-schema-enterprise-and-domain-admins/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>VBScript: Delete Files Older Than One Hour</title>
		<link>http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/</link>
		<comments>http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 06:08:32 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[vbScript]]></category>

		<guid isPermaLink="false">http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/</guid>
		<description><![CDATA[So, I am constantly looking for ways of automating tasks. Too many admins do not take advantage of scripting and scheduled tasks/cron. Just this last week, I was implementing a new print server. Besides just building up the new server, I wanted to actually offer the users something new and useful. I&#8217;ve been wanting to [...]]]></description>
			<content:encoded><![CDATA[<p>So, I am constantly looking for ways of automating tasks.  Too many admins do not take advantage of scripting and scheduled tasks/cron.  Just this last week, I was implementing a new print server.  Besides just building up the new server, I wanted to actually offer the users something new and useful.</p>
<p>I&#8217;ve been wanting to setup a network pdf printer for quite some time.  I have played around with setting up a <a href="http://www.novell.com/coolsolutions/feature/17636.html">network PDF printer using cups</a>.  However, we seem to be so MS centric these days that I decided to use <a href="http://www.pdfforge.org/products/pdfcreator">PDFCreator</a>&#8216;s print server.  It was really a piece of cake.  Just install the server portion, <a href="http://www.pdfforge.org/node/560">setup the service</a>, create a share and watch the PDF&#8217;s spool.</p>
<p>I quickly found that the folder where PDF&#8217;s were written to, was quickly filling with PDF&#8217;s as users were not removing them.  So, the solution was to write a little vbscript to purge any files older than an hour.  There were two things I wanted:</p>
<ol>
<li>I have a file named &#8220;!FILES ARE PURGED AFTER ONE HOUR!&#8221;.  I did not want this file removed.  It serves as a warning for uses.</li>
<li>I did not want to purge the folder every hour.  I wanted to remove any files that were one hour old or greater.  That way, if a user creates a PDF at 2:59pm, the 3:00pm run won&#8217;t delete it.  It will be deleted on or after 3:59pm.</li>
</ol>
<p>Here is the script I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">strFolder = <span style="color: #800000;">&quot;C:\Folder\&quot;</span>
<span style="color: #000080;">Set</span> objShell = CreateObject(<span style="color: #800000;">&quot;Shell.Application&quot;</span>)
<span style="color: #000080;">Set</span> objFolder = objShell.Namespace(strFolder)
<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
&nbsp;
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strFileName <span style="color: #000080;">in</span> objFolder.Items
    <span style="color: #000080;">If</span> len(objFSO.GetExtensionName(strFileName)) &gt; 0 <span style="color: #000080;">Then</span>
        <span style="color: #000080;">Set</span> objFile = objFSO.GetFile(strFolder &amp; strFileName.Name)
        <span style="color: #000080;">If</span> DateDiff(<span style="color: #800000;">&quot;N&quot;</span>,objFile.DateLastModified,Now()) &gt; 59 <span style="color: #000080;">Then</span>
            objFSO.DeleteFile(strFolder &amp; strFileName.Name),<span style="color: #000080;">True</span>
        <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">Next</span></pre></div></div>

<p>The great thing about this is that you get a free network PDF printer that can be left alone.  Your boss thinks you are a genius and there is no sweat on your brow.</p>
<p>Cheers!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;t=VBScript%3A+Delete+Files+Older+Than+One+Hour" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;title=VBScript%3A+Delete+Files+Older+Than+One+Hour&amp;summary=So%2C%20I%20am%20constantly%20looking%20for%20ways%20of%20automating%20tasks.%20%20Too%20many%20admins%20do%20not%20take%20advantage%20of%20scripting%20and%20scheduled%20tasks%2Fcron.%20%20Just%20this%20last%20week%2C%20I%20was%20implementing%20a%20new%20print%20server.%20%20Besides%20just%20building%20up%20the%20new%20server%2C%20I%20wanted%20to%20actually%20offer%20the%20users%20something%20new%20and%20useful&amp;source=Andrew Healey's Blog" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=VBScript%3A+Delete+Files+Older+Than+One+Hour+-+http://b2l.me/b4mjx&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-orkut">
			<a href="http://promote.orkut.com/preview?nt=orkut.com&amp;tt=VBScript%3A+Delete+Files+Older+Than+One+Hour&amp;du=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;cn=So%2C%20I%20am%20constantly%20looking%20for%20ways%20of%20automating%20tasks.%20%20Too%20many%20admins%20do%20not%20take%20advantage%20of%20scripting%20and%20scheduled%20tasks%2Fcron.%20%20Just%20this%20last%20week%2C%20I%20was%20implementing%20a%20new%20print%20server.%20%20Besides%20just%20building%20up%20the%20new%20server%2C%20I%20wanted%20to%20actually%20offer%20the%20users%20something%20new%20and%20useful" rel="nofollow" class="external" title="Promote this on Orkut">Promote this on Orkut</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;title=VBScript%3A+Delete+Files+Older+Than+One+Hour" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;submitHeadline=VBScript%3A+Delete+Files+Older+Than+One+Hour&amp;submitSummary=So%2C%20I%20am%20constantly%20looking%20for%20ways%20of%20automating%20tasks.%20%20Too%20many%20admins%20do%20not%20take%20advantage%20of%20scripting%20and%20scheduled%20tasks%2Fcron.%20%20Just%20this%20last%20week%2C%20I%20was%20implementing%20a%20new%20print%20server.%20%20Besides%20just%20building%20up%20the%20new%20server%2C%20I%20wanted%20to%20actually%20offer%20the%20users%20something%20new%20and%20useful&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22VBScript%3A%20Delete%20Files%20Older%20Than%20One%20Hour%22&amp;body=Link: http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A So%2C%20I%20am%20constantly%20looking%20for%20ways%20of%20automating%20tasks.%20%20Too%20many%20admins%20do%20not%20take%20advantage%20of%20scripting%20and%20scheduled%20tasks%2Fcron.%20%20Just%20this%20last%20week%2C%20I%20was%20implementing%20a%20new%20print%20server.%20%20Besides%20just%20building%20up%20the%20new%20server%2C%20I%20wanted%20to%20actually%20offer%20the%20users%20something%20new%20and%20useful" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://halfloaded.com/blog/vbscript-delete-all-files-older-than-one-hour/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.793 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-08-26 09:02:56 -->
<!-- Compression = gzip -->