<?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>SearchMarked.com &#187; VBScript</title>
	<atom:link href="http://www.searchmarked.com/category/vbscript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.searchmarked.com</link>
	<description>I search, I bookmark, I write, You learn.</description>
	<lastBuildDate>Wed, 14 Oct 2009 12:56:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to redirect output when using wscript.shell in vbscript</title>
		<link>http://www.searchmarked.com/vbscript/how-to-redirect-output-when-using-wscriptshell-in-vbscript.php</link>
		<comments>http://www.searchmarked.com/vbscript/how-to-redirect-output-when-using-wscriptshell-in-vbscript.php#comments</comments>
		<pubDate>Wed, 02 Jul 2008 19:34:31 +0000</pubDate>
		<dc:creator>hstagner</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.searchmarked.com/?p=78</guid>
		<description><![CDATA[Google Query: Wscript.Shell Application redirection output
I was trying to run ipconfig in one of my vbscripts using wscript.shell and the run method. However, I was trying to redirect the output to a text file. It just wasn&#8217;t working. It was a combination of those tricky double quotes and me not knowing the proper syntax to [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to redirect output when using wscript.shell in vbscript", url: "http://www.searchmarked.com/vbscript/how-to-redirect-output-when-using-wscriptshell-in-vbscript.php" });</script>


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Google Query: Wscript.Shell Application redirection output</strong></p>
<p>I was trying to run ipconfig in one of my vbscripts using wscript.shell and the run method. However, I was trying to redirect the output to a text file. It just wasn&#8217;t working. It was a combination of those tricky double quotes and me not knowing the proper syntax to accomplish this from inside a vbscript. Thankfully I found the answer quickly after some googling.</p>
<p>There was a <a href="http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=915" onclick="javascript:urchinTracker ('/outbound/article/www.scriptinganswers.com');">post at the ScriptingAnswers.com forum</a> that had a solution to my problem. Basically, it can be summed up with the following code:</p>
<p><code>Set objShell = WScript.CreateObject("WScript.Shell")<br />
strRun = "%comspec% /c ipconfig.exe &gt; " &amp; AddQuotes("C:\temp\ipconfig.txt")<br />
objShell.Run strRun, 1, True<br />
Function AddQuotes(strInput)<br />
AddQuotes = Chr(34) &amp; strInput &amp; Chr(34)<br />
End Function</code></p>
<p>The function AddQuotes takes care of the double quoting issues by surrounding whatever is input (using the <span style="text-decoration: line-through;">built in</span> strInput argument of the AddQuotes function.) into the AddQuotes function at the beginning of the script with additional quotes using the  built in Chr(34) function.</p>
<p>As for the %compspec% /c syntax. That is covered in this <a href="http://support.microsoft.com/kb/278411" onclick="javascript:urchinTracker ('/outbound/article/support.microsoft.com');">Microsoft KB Article</a>.</p>
<p>That&#8217;s it! You should now be able to redirect the output of any shell command using this technique. Happy Scripting!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/VBScript" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');">VBScript</a>, <a href="http://technorati.com/tag/Microsoft" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Microsoft</a>, <a href="http://technorati.com/tag/Windows" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Windows</a>, <a href="http://technorati.com/tag/Scripting" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Scripting</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=2b863fb9-6985-4119-9ea7-b8a518a3714e&amp;title=How+to+redirect+output+when+using+wscript.shell+in+vbscript&amp;url=http%3A%2F%2Fwww.searchmarked.com%2Fvbscript%2Fhow-to-redirect-output-when-using-wscriptshell-in-vbscript.php" onclick="javascript:urchinTracker ('/outbound/article/sharethis.com');">ShareThis</a></p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.searchmarked.com/vbscript/how-to-redirect-output-when-using-wscriptshell-in-vbscript.php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to hide typed passwords in a vbscript message box</title>
		<link>http://www.searchmarked.com/vbscript/how-to-hide-typed-passwords-in-a-vbscript-message-box.php</link>
		<comments>http://www.searchmarked.com/vbscript/how-to-hide-typed-passwords-in-a-vbscript-message-box.php#comments</comments>
		<pubDate>Wed, 02 Jul 2008 04:56:51 +0000</pubDate>
		<dc:creator>hstagner</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.searchmarked.com/?p=76</guid>
		<description><![CDATA[Google Query: hide password in vbscript
Sometimes you may need to prompt the user for a password in one of your vbscripts. No big deal right? It wouldn&#8217;t be except that the password can be seen in plain text as the user types it in. There is no way that I know of to hide the [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to hide typed passwords in a vbscript message box", url: "http://www.searchmarked.com/vbscript/how-to-hide-typed-passwords-in-a-vbscript-message-box.php" });</script>


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Google Query: hide password in vbscript</strong></p>
<p>Sometimes you may need to prompt the user for a password in one of your vbscripts. No big deal right? It wouldn&#8217;t be except that the password can be seen in plain text as the user types it in. There is no way that I know of to hide the password typed in with regular vbscript.</p>
<p>Fortunately, I found a very useful function at the <a href="http://quicktestprofessional.wordpress.com/2008/02/15/54/" onclick="javascript:urchinTracker ('/outbound/article/quicktestprofessional.wordpress.com');">Quick Test Professional blog</a>. It calls upon *shudder* Internet Explorer to create a password box for the user to type in the password. Because it uses Internet Explorer, the password field text is hidden when it is typed in. The code for the function, as well as an example of using it can be downloaded below (just change the *.txt extension to *.vbs).</p>
<p><strong><a href="http://www.searchmarked.com/wp-content/uploads/passwordbox-vbs.txt" >Download the Script here</a></strong></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/VBScript" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');">VBScript</a>, <a href="http://technorati.com/tag/Security" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Security</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=2b863fb9-6985-4119-9ea7-b8a518a3714e&amp;title=How+to+hide+typed+passwords+in+a+vbscript+message+box&amp;url=http%3A%2F%2Fwww.searchmarked.com%2Fvbscript%2Fhow-to-hide-typed-passwords-in-a-vbscript-message-box.php" onclick="javascript:urchinTracker ('/outbound/article/sharethis.com');">ShareThis</a></p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.searchmarked.com/vbscript/how-to-hide-typed-passwords-in-a-vbscript-message-box.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to pin a VBScript to the Windows start menu</title>
		<link>http://www.searchmarked.com/vbscript/how-to-pin-a-vbscript-to-the-windows-start-menu.php</link>
		<comments>http://www.searchmarked.com/vbscript/how-to-pin-a-vbscript-to-the-windows-start-menu.php#comments</comments>
		<pubDate>Wed, 02 Jul 2008 00:31:43 +0000</pubDate>
		<dc:creator>hstagner</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.searchmarked.com/?p=74</guid>
		<description><![CDATA[Google query: vbscript on start menu
I was playing around with one of the VBScripts that I written and I was trying to get it to pin to the start menu. The only problem is that pinning to the start menu is only available to applications. So I did some googling and came upon a post [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to pin a VBScript to the Windows start menu", url: "http://www.searchmarked.com/vbscript/how-to-pin-a-vbscript-to-the-windows-start-menu.php" });</script>


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Google query: vbscript on start menu</strong></p>
<p>I was playing around with one of the VBScripts that I written and I was trying to get it to pin to the start menu. The only problem is that pinning to the start menu is only available to applications. So I did some googling and came upon a post at <a href="http://renegadetech.blogspot.com/2006/07/how-to-convert-bat-file-or-vbs-file.html" onclick="javascript:urchinTracker ('/outbound/article/renegadetech.blogspot.com');">Renegade&#8217;s Random Tech Blog</a> that helped me indirectly.</p>
<p>I went through his instructions about using iexpress to package the vbscript file and they didn&#8217;t work for me (Sorry, Renegade). However, his post was the catalyst for my solution. One of the anonymous commenters mentioned that you could just do this with a shortcut. Here&#8217;s how:</p>
<p>-Create a new shortcut and point it to wscript.exe</p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/create-shortcut.png" alt="" width="319" height="236" /></p>
<p>-Click next and name the shortcut the same as your vbscript if you wish</p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/name-shortcut.png" alt="" width="319" height="236" /></p>
<p>-Click finish. You should now have a shortcut to wscript.exe (the windows script host used to execute vbscript. This by itself will not do what you want.</p>
<p>-Now right-click and go to the properties of your new shortcut.</p>
<p>-In the &#8220;Target:&#8221; field you should put the path to the vbscript file right after &#8220;%windir%\system32\wscript.exe&#8221; In my case, my complete &#8220;Target:&#8221; box looked like this:</p>
<p><code>%windir%\system32\wscript.exe c:\temp\searchmarked.vbs</code></p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/shortcut-properties.png" alt="" width="232" height="320" /></p>
<p>-Now click &#8220;OK&#8221;. You should be able to test the shortcut by double-clicking on it. What an awesome vbscript!</p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/vbscript-test.png" alt="" width="214" height="109" /></p>
<p>-Once you have verified that the shortcut worked, you can right-click on it and choose &#8220;pin to start menu.&#8221;</p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/start-menu-pin.png" alt="" width="232" height="320" /></p>
<p>-Voila! There is my vbscript pinned to the Windows start menu.</p>
<p><img src="http://i192.photobucket.com/albums/z293/hstagner/start-menu.png" alt="" width="189" height="320" /></p>
<p>That&#8217;s it! Happy Scripting!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/VBScript" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');">VBScript</a>, <a href="http://technorati.com/tag/Windows" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Windows</a>, <a href="http://technorati.com/tag/Scripting" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Scripting</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=2b863fb9-6985-4119-9ea7-b8a518a3714e&amp;title=How+to+pin+a+VBScript+to+the+Windows+start+menu&amp;url=http%3A%2F%2Fwww.searchmarked.com%2Fvbscript%2Fhow-to-pin-a-vbscript-to-the-windows-start-menu.php" onclick="javascript:urchinTracker ('/outbound/article/sharethis.com');">ShareThis</a></p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.searchmarked.com/vbscript/how-to-pin-a-vbscript-to-the-windows-start-menu.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to redirect users&#8217; favorites folder using VBScript</title>
		<link>http://www.searchmarked.com/windows/vbscript-for-folder-redirection-on-windows.php</link>
		<comments>http://www.searchmarked.com/windows/vbscript-for-folder-redirection-on-windows.php#comments</comments>
		<pubDate>Mon, 28 Jan 2008 19:05:57 +0000</pubDate>
		<dc:creator>hstagner</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://www.searchmarked.com/windows/vbscript-for-folder-redirection-on-windows.php</guid>
		<description><![CDATA[Searchmarked.com Tip
Update: wnaquin in the comments below pointed out that the users&#8217; actual favorites were not in the new location. Keep in mind that this script does not actually copy any data to the new location. So this will work for new users, but for existing users you will have to copy their data manually [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to redirect users&#8217; favorites folder using VBScript", url: "http://www.searchmarked.com/windows/vbscript-for-folder-redirection-on-windows.php" });</script>


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Searchmarked.com Tip</strong></p>
<p><strong>Update: wnaquin in the comments below pointed out that the users&#8217; actual favorites were not in the new location. Keep in mind that this script does not actually copy any data to the new location. So this will work for new users, but for existing users you will have to copy their data manually or through a logon script. The below .bat or .cmd file should work:</strong></p>
<p><code>@echo off<br />
REM # The below line creates the directory structure.<br />
xcopy "%userprofile%\favorites" "\\Server\share\%username%\favorites" /i /t /q /y<br />
REM # The below line copies the files.<br />
xcopy "%userprofile%\favorites" "\\Server\share\%username%\favorites" /i /q /y</code></p>
<p>Every Windows System administrator knows what a pain user profiles can be. This is especially true if they are roaming profiles. That is why I have made it my personal mission to rid the world of roaming profiles. I have enabled folder redirection at work through Group Policy. This works for the &#8220;Application Data&#8221;, &#8220;My Documents&#8221;, and &#8220;Desktop&#8221; folders.</p>
<p>However, in Microsoft&#8217;s infinite wisdom, they decided to leave out the one folder that will make our users scream the loudest. The &#8220;Favorites&#8221; folder. There is no setting in Group Policy for the &#8220;Favorites&#8221; folder. So I had to script it. Below are the results in VBScript.</p>
<p><code>'==========================================================================<br />
'<br />
' NAME: fav_redirect.vbs<br />
'<br />
' AUTHOR: Harley Stagner<br />
' DATE  : 1/24/2008<br />
'<br />
' COMMENT: This script will redirect users folders to the File server<br />
'		    yourfileserver<br />
'==========================================================================<br />
'**************************************************************************<br />
'********************************Header Section*****************************<br />
'**************************************************************************<br />
<span style="color: #0000ff;"> Option Explicit</span><br />
'Variable for shell object<br />
<span style="color: #0000ff;"> Dim</span> <span style="color: #000000;">wshShell</span><br />
'Variable for redirecting Favorites<br />
<span style="color: #0000ff;"> Dim</span> <span style="color: #000000;">strFavoriteRedirectRegKey</span><br />
<span style="color: #0000ff;"> Dim</span> <span style="color: #000000;">strFavoriteRedirectLocation</span><br />
<span style="color: #0000ff;"> Dim</span> <span style="color: #000000;">strFavoriteRedirectRegType</span><br />
'**************************************************************************<br />
'********************************Reference Section**************************<br />
'**************************************************************************<br />
'CREATE GLOBAL OBJECTS<br />
<span style="color: #0000ff;"> Set</span> <span style="color: #000000;">wshShell = CreateObject(<span style="color: #999999;">"WScript.Shell"</span>)</span><br />
' INITIALIZE VARIABLES----------------------------------------------------------------------------------------------<br />
'Favorites Redirection Registry Info<br />
<span style="color: #000000;"> strFavoriteRedirectRegKey =</span> <span style="color: #999999;">"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites"</span><br />
<span style="color: #000000;"> strFavoriteRedirectLocation =</span> <span style="color: #999999;">"\\YOURFILESERVER\Redirected Folders\%username%\Favorites"</span><br />
<span style="color: #000000;"> strFavoriteRedirectRegType = </span><span style="color: #999999;">"REG_EXPAND_SZ"</span><br />
'**************************************************************************<br />
'**********************************Worker/Output Section********************<br />
'**************************************************************************<br />
'Redirect Favorites by writing registry entry.<br />
<span style="color: #000000;"> wshShell.RegWrite strFavoriteRedirectRegKey, strFavoriteRedirectLocation, strFavoriteRedirectRegType</span></code></p>
<p>Just copy and paste the code into notepad and save the file with a *.vbs extension and you&#8217;re ready to rock. You will need to replace some information in the script with details that are specific to your environment (like the redirection location). Also keep in mind that the initialization of the variables are one variable per line. For example, where it says &#8220;strFavoriteRedirectRegKey= Some value&#8221; that statement should be on one line. Also the statement:</p>
<p><span style="color: #000000;"><code> wshShell.RegWrite strFavoriteRedirectRegKey, strFavoriteRedirectLocation, strFavoriteRedirectRegType</code></span></p>
<p>Should be on one line. The formatting of the web page throws this off sometimes.</p>
<p>You can either run the script locally (to test its functionality) or you can set this as a login script for users via Active Directory Group Policy. That&#8217;s it! Happy folder redirecting!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/Windows" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');">Windows</a>, <a href="http://technorati.com/tag/Active+Directory" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Active Directory</a>, <a href="http://technorati.com/tag/VBScript" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> VBScript</a>, <a href="http://technorati.com/tag/Windows+Scripting" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Windows Scripting</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=2b863fb9-6985-4119-9ea7-b8a518a3714e&amp;title=How+to+redirect+users%26%238217%3B+favorites+folder+using+VBScript&amp;url=http%3A%2F%2Fwww.searchmarked.com%2Fwindows%2Fvbscript-for-folder-redirection-on-windows.php" onclick="javascript:urchinTracker ('/outbound/article/sharethis.com');">ShareThis</a></p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.searchmarked.com/windows/vbscript-for-folder-redirection-on-windows.php/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to get a computer&#8217;s Active Directory OU using VBScript</title>
		<link>http://www.searchmarked.com/windows/how-to-get-a-computers-active-directory-ou-using-vbscript.php</link>
		<comments>http://www.searchmarked.com/windows/how-to-get-a-computers-active-directory-ou-using-vbscript.php#comments</comments>
		<pubDate>Fri, 21 Dec 2007 03:12:17 +0000</pubDate>
		<dc:creator>hstagner</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.searchmarked.com/windows/how-to-get-a-computers-active-directory-ou-using-vbscript.php</guid>
		<description><![CDATA[

   var AdBrite_Title_Color = 'FFFFFF';
   var AdBrite_Text_Color = '000000';
   var AdBrite_Background_Color = '000000';
   var AdBrite_Border_Color = '2D8930';
   var AdBrite_URL_Color = '008000';


Your Ad Here

Google Query: get computer&#8217;s ou with vbscript
I was working on a project for work today where I had to use a script to [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to get a computer&#8217;s Active Directory OU using VBScript", url: "http://www.searchmarked.com/windows/how-to-get-a-computers-active-directory-ou-using-vbscript.php" });</script>


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<div style="float: left;"><!-- Begin: AdBrite --><br />
<script type="text/javascript">
   var AdBrite_Title_Color = 'FFFFFF';
   var AdBrite_Text_Color = '000000';
   var AdBrite_Background_Color = '000000';
   var AdBrite_Border_Color = '2D8930';
   var AdBrite_URL_Color = '008000';
</script><br />
<script src="http://ads.adbrite.com/mb/text_group.php?sid=745476&#038;zs=3330305f323530" type="text/javascript"></script></p>
<div><a href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=745476&#038;afsid=1"target="_top"  style="font-weight:bold;font-family:Arial;font-size:13px;" onclick="javascript:urchinTracker ('/outbound/article/www.adbrite.com');">Your Ad Here</a></div>
<p><!-- End: AdBrite --></div>
<p><strong>Google Query: get computer&#8217;s ou with vbscript</strong></p>
<p>I was working on a project for work today where I had to use a script to get a computer&#8217;s Active Directory OU and take an action based on the OU that the computer was in. This project will eventually become a logon script. Since our network consists of a mixture of Windows 2000 and Windows XP computers, Powershell was out of the question. It was time to turn to the tried and true VBScript and its fifty-million lines of code to accomplish one small task.</p>
<p>There are a couple of ways that I could query for the computer&#8217;s OU using VBScript. I could connect to Active Directory and walk the whole directory tree but this could take a while. I could dump the contents of the Active Directory tree into a text file and search on it, but that is messy. Fortunately, I found the gem of a snippet below at the <a href="http://www.tek-tips.com/viewthread.cfm?qid=1098379&amp;page=2" onclick="javascript:urchinTracker ('/outbound/article/www.tek-tips.com');">Tek-Tips Forums</a>. It was posted by PScottC.<br />
<code>Dim wshShell, wshNetwork<br />
Dim strComputerName<br />
' Create Global Objects<br />
Set wshShell = CreateObject("WScript.Shell")<br />
Set wshNetwork = CreateObject("WScript.Network")<br />
' Initialize Variables<br />
strComputerName = wshNetwork.ComputerName<br />
wscript.echo "Computer DN: " &amp; GetDN<br />
Function GetDN()<br />
' Use the NameTranslate object to convert the NT name of the computer to<br />
' the Distinguished name required for the LDAP provider. Computer names<br />
' must end with "$". Returns comma delimited string to calling code.<br />
Dim objTrans, objDomain<br />
' Constants for the NameTranslate object.<br />
Const ADS_NAME_INITTYPE_GC = 3<br />
Const ADS_NAME_TYPE_NT4 = 3<br />
Const ADS_NAME_TYPE_1779 = 1<br />
Set objTrans = CreateObject("NameTranslate")<br />
Set objDomain = getObject("LDAP://rootDse")<br />
objTrans.Init ADS_NAME_INITTYPE_GC, ""<br />
objTrans.Set ADS_NAME_TYPE_NT4, wshNetwork.UserDomain &amp; "\" _<br />
&amp; strComputerName &amp; "$"<br />
GetDN = objTrans.Get(ADS_NAME_TYPE_1779)<br />
'Set DN to upper Case<br />
GetDN = UCase(GetDN)<br />
End Function</code></p>
<p>Basically, this script snippet can be used to convert an NT computer name into a the full Active Directory Distinguished Name for the computer. The following line:<br />
<code>wscript.echo "Computer DN: " &amp; GetDN</code></p>
<p>Is merely there as a placeholder to show you the output of the &#8220;GetDN&#8221; function at the end of the script. You can replace it with any code you choose. If you want the script to do something different based on the computer&#8217;s OU then the natural choice would be to use the &#8220;GetDN&#8221; value in an &#8220;elseif&#8221; or &#8220;case&#8221; statement. When I have my full script complete using this code snippet, I will share the details. Until then&#8230;<br />
Happy Coding!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/Windows" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');">Windows</a>, <a href="http://technorati.com/tag/Scripting" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> Scripting</a>, <a href="http://technorati.com/tag/VBScript" rel="tag" onclick="javascript:urchinTracker ('/outbound/article/technorati.com');"> VBScript</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=2b863fb9-6985-4119-9ea7-b8a518a3714e&amp;title=How+to+get+a+computer%26%238217%3Bs+Active+Directory+OU+using+VBScript&amp;url=http%3A%2F%2Fwww.searchmarked.com%2Fwindows%2Fhow-to-get-a-computers-active-directory-ou-using-vbscript.php" onclick="javascript:urchinTracker ('/outbound/article/sharethis.com');">ShareThis</a></p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.searchmarked.com/windows/how-to-get-a-computers-active-directory-ou-using-vbscript.php/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
