<?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>108.bz &#187; VBScript</title>
	<atom:link href="http://www.108.bz/posts/tag/vbscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.108.bz</link>
	<description>Wandering futilities...</description>
	<lastBuildDate>Fri, 27 May 2011 09:08:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Symantec Endpoint Protection &#8211; crypt32 errors</title>
		<link>http://www.108.bz/posts/it/symantec-endpoint-protection-crypt32-errors/</link>
		<comments>http://www.108.bz/posts/it/symantec-endpoint-protection-crypt32-errors/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 16:28:58 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Group Policy]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Symantec]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=591</guid>
		<description><![CDATA[One of the most procrastinated issues I had at a Customer&#8217;s, was the proliferation of errors like these (as shown in servers/clients Event Viewer): Event Type: Error Event Source: &#160; crypt32 Event Category: None Event ID: &#160; 8 Description: Failed auto update retrieval of third-party root list sequence number from: &#60;http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootseq.txt&#62; with error: This network [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most procrastinated issues I had at a Customer&#8217;s, was the proliferation of errors like these (as shown in servers/clients Event Viewer):</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Event Type: Error<br />
Event Source: &nbsp; crypt32<br />
Event Category: None<br />
Event ID: &nbsp; 8<br />
Description:<br />
Failed auto update retrieval of third-party root list sequence number from: &lt;http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootseq.txt&gt; with error: This network connection does not exist.</div></div>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Event Type: Error<br />
Event Source: &nbsp; crypt32<br />
Event Category: None<br />
Event ID: &nbsp; 11<br />
Description:<br />
Failed extract of third-party root list from auto update cab at: &lt;http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootstl.cab&gt; with error: A required certificate is not within its validity period when verifying against the current system clock or the timestamp in the signed file.</div></div>
<p>There are several posts mentioning the issue, <a href="http://www.symantec.com/connect/forums/crypt32-errors-event-viewer-after-sep-110-installation">this one</a> pointed me in the right direction. Basically, because of how SEP components communicate, Windows is triggered into updating the list of trusted root Certification Authorities. It tries to do so through the Internet using the Computer account. The latter may not have any proxy configured. Being unable to reach outside, the host gets flooded by <i>crypt32</i> errors.</p>
<p>In order to solve the issue, I decided to deploy a valid proxy configuration, for the Computer account (<i>SYSTEM</i> user), on a subset of the Domain&#8217;s hosts.<br />
One of the ways to script that is the &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">proxycfg -u</span>&#8221; command<sup class='footnote'><a href='#fn-591-1' id='fnref-591-1'>1</a></sup> that works by copying the current user proxy settings to the SYSTEM&#8217;s registry. Sounds cool but if the current user is not a member of the local Administrators group, he won&#8217;t have the necessary rights. The following script instead, can be launched via Group Policy<sup class='footnote'><a href='#fn-591-2' id='fnref-591-2'>2</a></sup> during operating system startup, and since it&#8217;s a <i>startup</i> script rather than a <i>login</i> one, it will run with administrative privileges.</p>
<p>Nothing fancy in the below source. It creates the registry key if it doesn&#8217;t exist, then sets the right value for <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">WinHttpSettings</span> which I obtained this way:</p>
<ul>
<li>use &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">proxycfg -u</span>&#8221; on a test host</li>
<li>use the Registry editor to export the contents of <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections</span></li>
</ul>
<p>The value is of type <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">REG_BINARY</span>. Since the <a href="http://msdn.microsoft.com/en-us/library/yfdfhz1b(v=vs.85).aspx">RegWrite</a> API (method of class <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">WScript.Shell</span>) cannot deal with binary values, WMI (<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">StdRegProv</span> registry provider) needs to be used. Also, <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">SetBinaryValue</span> expects an array of decimal values, while Regedit exports them as hexadecimal digits (you&#8217;ll have to take care of the conversion yourself).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span><br />
<span style="color: #000080;">Const</span> HKEY_LOCAL_MACHINE = &amp;H80000002<br />
<br />
strPath = <span style="color: #800000;">&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections&quot;</span><br />
strKey = <span style="color: #800000;">&quot;WinHttpSettings&quot;</span><br />
strValue = <span style="color: #800000;">&quot;24,0,0,0,0,0,0,0,3,0,0,0,19,0,0,0,112,114,111,120,121,46,99,117,115,116,46,108,97,110,58,56,48,56,48,47,0,0,0,49,48,46,42,46,42,46,42,59,115,101,114,118,101,114,50,48,59,115,101,114,118,101,114,50,48,46,42,59,42,46,99,117,115,116,46,108,97,110,59,60,108,111,99,97,108,62&quot;</span><br />
strMachineName = <span style="color: #800000;">&quot;.&quot;</span><br />
<br />
arrValues = Split(strValue,<span style="color: #800000;">&quot;,&quot;</span>)<br />
strMoniker = <span style="color: #800000;">&quot;winMgmts:\\&quot;</span> &amp; strMachineName &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span><br />
<span style="color: #000080;">Set</span> oReg = GetObject(strMoniker)<br />
rv = oReg.CreateKey(HKEY_LOCAL_MACHINE, strPath)<br />
rv = oReg.SetBinaryValue(HKEY_LOCAL_MACHINE, strPath, strKey, arrValues)</div></div>
<p>If the scripts works as it should, you&#8217;ll be greeted by these events:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Event Type: Information<br />
Event Source: &nbsp; crypt32<br />
Event Category: None<br />
Event ID: &nbsp; 7<br />
Description:<br />
Successful auto update retrieval of third-party root list sequence number from: &lt;http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootseq.txt&gt;</div></div>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Event Type: Information<br />
Event Source: &nbsp; crypt32<br />
Event Category: None<br />
Event ID: &nbsp; 2<br />
Description:<br />
Successful auto update retrieval of third-party root list cab from: &lt;http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootstl.cab&gt;</div></div>
<p>And, hopefully, crypt32 errors will be gone for good.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-591-1'>See <a href="http://msdn.microsoft.com/en-us/library/ms761351(v=vs.85).aspx">Using the WinHTTP Proxy Configuration Utility</a> <span class='footnotereverse'><a href='#fnref-591-1'>&#8617;</a></span></li>
<li id='fn-591-2'>Computer Configuration, Windows Settings, Scripts, Startup <span class='footnotereverse'><a href='#fnref-591-2'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=591" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/symantec-endpoint-protection-crypt32-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulk unlocking Active Directory user accounts</title>
		<link>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/</link>
		<comments>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/#comments</comments>
		<pubDate>Sat, 15 May 2010 22:23:59 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=475</guid>
		<description><![CDATA[This post will show you how to generate a list of all the users&#8217; Distinguished Name, then filter it, then do something useful with it. Scenario: saturday morning (after having crashed into bed at 4:00 a.m., btw), Customer calls. A virus hit the Company and one of the most annoying consequences of the outburst, is [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to generate a list of all the users&#8217; <a href="http://en.wikipedia.org/wiki/Distinguished_Name">Distinguished Name</a>, then filter it, then do something useful with it.</p>
<p>Scenario: saturday morning (after having crashed into bed at 4:00 a.m., btw), Customer calls. A virus hit the Company and one of the most annoying consequences of the outburst, is that every domain user account gets locked due to brute-force login attempts (as per the &#8220;Account Lockout Threshold&#8221; <a href="http://technet.microsoft.com/en-us/library/dd277400.aspx">policy</a>). While they run around cleaning PCs and fixing A/V installations<sup class='footnote'><a href='#fn-475-1' id='fnref-475-1'>1</a></sup>, I&#8217;m asked for a method to quickly unlock the accounts.</p>
<p>I tend to carry out these kind of tasks &#8220;the Unix way&#8221;, using the available DOS prompt commands and a bit of VBScript.</p>
<ul>
<li>Start off by calling LDIFDE:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ldifde -r &quot;(objectclass=user)&quot; -l sAMAccountName -m -f users.ldf</div></div>
<p><a href="http://support.microsoft.com/kb/237677">LDIFDE</a> exports/imports Active Directory data to/from properly formatted (<a href="http://en.wikipedia.org/wiki/LDIF">LDIF</a>) text files. I use it a lot. Ran as shown above, LDIFDE exports the objects of class &#8220;user&#8221; into a file named <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">users.ldf</span> . Of the many attributes an LDAP object bears, I tell LDIFDE to output just the &#8220;sAMAccountName&#8221; one. If I hadn&#8217;t specified any attribute, in the resulting file I&#8217;d have found duplicate DNs for the same user. That&#8217;s because of how the resulting LDIF file is described. Some A/D data is &#8220;incrementally&#8221; added to existing objects given their DN. I just picked sAMAccountName because every user has one and, also, to keep the file small.</li>
<li>Then:
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">findstr /I /b dn.*ou=service.users users.ldf &gt; service_users.txt<br />
findstr /I /b dn.*cn=users users.ldf &gt; normal_users.txt</div></div>
<p><a href="http://technet.microsoft.com/en-us/library/bb490907.aspx">findstr</a> is Microsoft&#8217;s &#8220;poor man version&#8221; of <a href="http://en.wikipedia.org/wiki/Grep">grep</a>, supporting a subset of the regular expression everyone has or should&#8217;ve come to love. Here I&#8217;m using it to extract Distinguished Names from the LDIF (only the ones that lie in a given Organizational Unit), and saving them to the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">*_users.txt</span> files. They will look like:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dn: CN=squidauth,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=exchangebackup,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=ldap,OU=Service Users,DC=contoso,DC=com<br />
dn: CN=batchcopy,OU=Service Users,DC=contoso,DC=com</div></div>
</li>
<li>Here&#8217;s the VBScript function to unlock an account given its DN:
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Sub</span> unlockuser(userDN)<br />
&nbsp; <span style="color: #000080;">Set</span> objUser = GetObject (<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; userDN)<br />
&nbsp; objUser.IsAccountLocked = <span style="color: #000080;">False</span><br />
&nbsp; objUser.SetInfo<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></div></div>
<p>We just need to transform findstr&#8217;s output, substituting the leading &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">dn: </span>&#8221; with &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span>&#8221; and enclosing in double quotes what follows. At the top of the new, transformed, file, we&#8217;ll copy/paste <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span> subroutine definition. That&#8217;ll make our final script.</li>
<li>How to carry out the transform? Using this VBS snippet; it processes its <a href="http://en.wikipedia.org/wiki/Standard_input">Standard Input</a> line by line, and outputs the modifications on Standard Output, just like any Unix file filtering command.
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Set</span> StdIn = WScript.StdIn <br />
<span style="color: #000080;">Do</span> <span style="color: #000080;">While</span> <span style="color: #000080;">Not</span> StdIn.AtEndOfStream <br />
&nbsp; &nbsp; <span style="color: #000080;">line</span> = stdin.readline<br />
&nbsp; &nbsp; <span style="color: #000080;">line</span> = right(<span style="color: #000080;">line</span>,len(<span style="color: #000080;">line</span>)-4)<br />
&nbsp; &nbsp; wscript.echo <span style="color: #800000;">&quot;unlockuser &quot;</span><span style="color: #800000;">&quot;&quot;</span> &amp; <span style="color: #000080;">line</span> &amp; <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot;&quot;</span><br />
<span style="color: #000080;">Loop</span></div></div>
<p>I saved it in a &#8220;<span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">dnfilter.vbs</span>&#8221; file and used it this way:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">type service_users.txt | cscript /nologo dnfilter.vbs &gt; unlock_service_users.vbs</div></div>
<p>To obtain something like this:</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">unlockuser <span style="color: #800000;">&quot;CN=squidauth,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=exchangebackup,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=ldap,OU=Service Users,DC=contoso,DC=com&quot;</span><br />
unlockuser <span style="color: #800000;">&quot;CN=batchcopy,OU=Service Users,DC=contoso,DC=com&quot;</span></div></div>
</li>
</ul>
<p>As I said, add the <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlockuser</span> function at the top of <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">unlock_service_users.vbs</span> and you&#8217;ll have your bulk unlocking script.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-475-1'>A/V usefulness is often questionable. At least three times a year an unfortunate Customer gets infected by a 0-day threat&#8230; <img src='http://www.108.bz/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <span class='footnotereverse'><a href='#fnref-475-1'>&#8617;</a></span></li>
</ol>
</div>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=475" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/bulk-unlocking-active-directory-user-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

