<?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>danejeffrey.com &#187; vbscript</title>
	<atom:link href="http://danejeffrey.com/blog/tag/vbscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://danejeffrey.com/blog</link>
	<description>Good ways to break things.</description>
	<lastBuildDate>Wed, 05 Oct 2011 00:13:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Active Directory Site and Subnet List VBScript</title>
		<link>http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/</link>
		<comments>http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 05:45:50 +0000</pubDate>
		<dc:creator>danejeff</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://danejeffrey.com/blog/?p=463</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/' addthis:title='Active Directory Site and Subnet List VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>This will list Active Directory sites and subnets and display in a MsgBox. Formatting is ugly but that&#8217;s easy to change as required. 'Get list of AD subnets Set oRootDSE = GetObject("LDAP://RootDSE") sConfigurationNC = oRootDSE.Get("configurationNamingContext") Set oRootDSE = Nothing sSubnetsContainer = "LDAP://cn=Subnets,cn=Sites" &#38; "," &#38; sConfigurationNC Set oSubnetsContainer = GetObject(sSubnetsContainer) For Each sResult In oSubnetsContainer [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/' addthis:title='Active Directory Site and Subnet List VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/' addthis:title='Active Directory Site and Subnet List VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>This will list Active Directory sites and subnets and display in a MsgBox. Formatting is ugly but that&#8217;s easy to change as required.</p>
<pre class="brush:vb">'Get list of AD subnets

Set oRootDSE = GetObject("LDAP://RootDSE")
sConfigurationNC = oRootDSE.Get("configurationNamingContext")
Set oRootDSE = Nothing 

sSubnetsContainer = "LDAP://cn=Subnets,cn=Sites" &amp; "," &amp; sConfigurationNC
Set oSubnetsContainer = GetObject(sSubnetsContainer)

For Each sResult In oSubnetsContainer

	aSNInfo = Split(sResult.cn, "/")
	If Instr(sResult.siteObject, ",") = 0 Then
		sSN = sSN &amp; aSNInfo(0) &amp; vbTab &amp; vbTab
	Else
		sSN = sSN &amp; aSNInfo(0) &amp; ": " &amp; _
			Mid(Left(sResult.siteObject, Instr(sResult.siteObject, ",") - 1), 4) &amp; _
			vbTab &amp; vbTab
	End if
Next
wscript.echo sSN</pre>
<p>To display your computer&#8217;s site:</p>
<pre class="brush:vb">Set adsSystemInfo = CreateObject("ADSystemInfo")
WScript.echo "Your site is: " &amp; adsSystemInfo.SiteName
Set adsSystemInfo = Nothing</pre>
<img src="http://danejeffrey.com/blog/?ak_action=api_record_view&id=463&type=feed" alt="" /><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/' addthis:title='Active Directory Site and Subnet List VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://danejeffrey.com/blog/2011/01/04/active-directory-site-and-subnet-list-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Get Using MSXML2.XMLHTTP Object VBScript</title>
		<link>http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/</link>
		<comments>http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 05:41:16 +0000</pubDate>
		<dc:creator>danejeff</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://danejeffrey.com/blog/?p=461</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/' addthis:title='HTTP Get Using MSXML2.XMLHTTP Object VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Use the XMLHTTP object to issue an HTTP Get on a remote web server. Set objHTTP = CreateObject("MSXML2.XMLHTTP") objHTTP.open "GET", "http://localhost/default.htm, False objHTTP.send strResponse = objHTTP.responseText Ref: http://msdn.microsoft.com/en-us/library/ms757849(VS.85).aspx<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/' addthis:title='HTTP Get Using MSXML2.XMLHTTP Object VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/' addthis:title='HTTP Get Using MSXML2.XMLHTTP Object VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Use the XMLHTTP object to issue an HTTP Get on a remote web server.</p>
<pre class="brush:vb">Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.open "GET", "http://localhost/default.htm, False
objHTTP.send
strResponse = objHTTP.responseText</pre>
<p>Ref: <a href="http://msdn.microsoft.com/en-us/library/ms757849(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms757849(VS.85).aspx</a></p>
<img src="http://danejeffrey.com/blog/?ak_action=api_record_view&id=461&type=feed" alt="" /><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/' addthis:title='HTTP Get Using MSXML2.XMLHTTP Object VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://danejeffrey.com/blog/2010/12/23/http-get-using-msxml2-xmlhttp-object-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory LDAP / SQL Query Syntax VBScript</title>
		<link>http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/</link>
		<comments>http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 05:23:45 +0000</pubDate>
		<dc:creator>danejeff</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://danejeffrey.com/blog/?p=452</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/' addthis:title='Active Directory LDAP / SQL Query Syntax VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Sample VBscript to query Active Directory for certain object properties. Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE objCommand.Properties("Sort On") = "sn" '.::LDAP Query Syntax::. strBase = "&#60;LDAP://dc=contoso,dc=com&#62;" ' Update with your domain [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/' addthis:title='Active Directory LDAP / SQL Query Syntax VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/' addthis:title='Active Directory LDAP / SQL Query Syntax VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Sample VBscript to query Active Directory for certain object properties.</p>
<pre class="brush:as3">Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort On") = "sn"

'.::LDAP Query Syntax::.
strBase = "&lt;LDAP://dc=contoso,dc=com&gt;" ' Update with your domain
strFilter = "(&amp;(objectCategory=person)(objectClass=user))"
strReturnAttribs = "sn,givenName,mail,sAMAccountName"
strQuery = strBase &amp; ";" &amp; strFilter &amp; ";" &amp; strReturnAttribs &amp; ";subtree"
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
   ' Loop through the record set results (each row could be written to a file or echo'd as below or ...)
    Wscript.Echo objRecordSet.Fields("sn").Value &amp; _
"," &amp; objRecordSet.Fields("givenName").Value &amp; _
"," &amp; objRecordSet.Fields("mail").Value &amp; _
"," &amp; objRecordSet.Fields("sAMAccountName").Value &amp; _
objRecordSet.MoveNext
Loop</pre>
<p>To use SQL query syntax to return properties for a user, the query might look like:</p>
<pre class="brush:as3">'.::SQL Syntax Query::.
sUser = "bob"
objCommand.CommandText = _
    "SELECT givenName, sn, mail FROM 'LDAP://dc=contoso,dc=com' WHERE objectCategory='user' AND sAMAccountName='" &#038; sUser &#038; "'"</pre>
<img src="http://danejeffrey.com/blog/?ak_action=api_record_view&id=452&type=feed" alt="" /><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/' addthis:title='Active Directory LDAP / SQL Query Syntax VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://danejeffrey.com/blog/2010/12/23/active-directory-ldap-query-syntax-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FileSystemObject Create A Text File VBScript</title>
		<link>http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/</link>
		<comments>http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 05:07:19 +0000</pubDate>
		<dc:creator>danejeff</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://danejeffrey.com/blog/?p=447</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/' addthis:title='FileSystemObject Create A Text File VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Creates a new text file and writes a line to it. That is all. TargetFile = "myfile.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(TargetFile, True) 'The 'True' parameter means overwrite existing file if it exists File.WriteLine "my line inside the file" objFile.Close Set objFSO = Nothing<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/' addthis:title='FileSystemObject Create A Text File VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/' addthis:title='FileSystemObject Create A Text File VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Creates a new text file and writes a line to it. That is all.</p>
<pre class="brush:vb">TargetFile = "myfile.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(TargetFile, True)      'The 'True' parameter means overwrite existing file if it exists
File.WriteLine "my line inside the file"
objFile.Close
Set objFSO = Nothing</pre>
<img src="http://danejeffrey.com/blog/?ak_action=api_record_view&id=447&type=feed" alt="" /><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/' addthis:title='FileSystemObject Create A Text File VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://danejeffrey.com/blog/2010/12/23/filesystemobject-create-a-text-file-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory Bind VBScript</title>
		<link>http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/</link>
		<comments>http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 03:02:13 +0000</pubDate>
		<dc:creator>danejeff</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://danejeffrey.com/blog/?p=445</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/' addthis:title='Active Directory Bind VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>'Bind to Active Directory Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("DefaultNamingContext")<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/' addthis:title='Active Directory Bind VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/' addthis:title='Active Directory Bind VBScript '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><pre class="brush:vb">'Bind to Active Directory
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")</pre>
<img src="http://danejeffrey.com/blog/?ak_action=api_record_view&id=445&type=feed" alt="" /><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/' addthis:title='Active Directory Bind VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://danejeffrey.com/blog/2010/12/23/active-directory-bind-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

