<?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>Bahramov's Personal Blog &#187; Active Directory</title>
	<atom:link href="http://www.bahramov.com/tag/active-directory/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bahramov.com</link>
	<description>Computers, databases, networks and virtualization</description>
	<lastBuildDate>Wed, 28 Apr 2010 12:24:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>VB Script to query domain computers for currently logged in users</title>
		<link>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 09:34:42 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Active Directory]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/</guid>
		<description><![CDATA[Source: http://forum.vingrad.ru/forum/topic-154708/view-all.html
The script will query domain computers for logged on users on each computer


&#039; The script will query domain computers for logged on users
&#039; on each computer
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRoot = GetObject(&#34;LDAP://RootDSE&#34;)
strDomainName = objRoot.Get(&#34;DefaultNamingContext&#34;)
Set objRoot = Nothing

strComputer = &#34;&#34;
Dim fso
Dim file

Set fso = CreateObject(&#34;Scripting.FileSystemObject&#34;)
Set file = fso.OpenTextFile (&#34;logged_user_list.txt&#34;, 2, True)
Set objShell [...]]]></description>
			<content:encoded><![CDATA[<div class="csharpcode">Source: <a title="http://forum.vingrad.ru/forum/topic-154708/view-all.html" href="http://forum.vingrad.ru/forum/topic-154708/view-all.html">http://forum.vingrad.ru/forum/topic-154708/view-all.html</a></div>
<div>The script will query domain computers for logged on users on each computer</div>
<div><span id="more-309"></span></div>
<div>
<pre class="brush: vb.net">&#039; The script will query domain computers for logged on users
&#039; on each computer
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRoot = GetObject(&quot;LDAP://RootDSE&quot;)
strDomainName = objRoot.Get(&quot;DefaultNamingContext&quot;)
Set objRoot = Nothing

strComputer = &quot;&quot;
Dim fso
Dim file

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set file = fso.OpenTextFile (&quot;logged_user_list.txt&quot;, 2, True)
Set objShell = CreateObject(&quot;WScript.Shell&quot;)

Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)
Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
objConnection.Provider = &quot;ADsDSOObject&quot;
objConnection.Open &quot;Active Directory Provider&quot;

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = &quot;Select Name, Location from &#039;LDAP://&quot; &amp; strDomainName &amp; &quot;&#039;&quot; _
&amp; &quot;Where objectClass =&#039;computer&#039;&quot;
objCommand.Properties(&quot;Page Size&quot;) = 1000
objCommand.Properties(&quot;Searchscope&quot;) = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute

&#039;**********************************************************************************

objRecordSet.MoveFirst

Wscript.Echo &quot;Processing information. This might take several minutes.&quot;

Do Until objRecordSet.EOF
    strComputer = objRecordSet.Fields(&quot;Name&quot;).Value

&#039; Check computer online status by using PING
&#039; and analysing output

    Set objScriptExec = objShell.Exec(&quot;%comspec% /c ping.exe -n 1 &quot; &amp; strComputer)
    strPingResults = LCase(objScriptExec.StdOut.ReadAll)

&#039;    If computer responds, connect to WMI

    If InStr(strPingResults, &quot;ttl=&quot;) Then
     Set objWMIService = GetObject(&quot;winmgmts:&quot; _
    &amp; &quot;{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)
      
        Set colComputer = objWMIService.ExecQuery _
    (&quot;Select * from Win32_ComputerSystem&quot;)
  
&#039; List logged on users to file and screen

        For Each objComputer in colComputer
             WScript.Echo &quot;Logged-on &quot; &amp;strComputer &amp; &quot; user: &quot; &amp; objComputer.UserName
             file.WriteLine(&quot;Logged-on &quot; &amp;strComputer &amp; &quot; user: &quot; &amp; objComputer.UserName)
        Next
        objRecordSet.MoveNext
      
&#039; If computer does not respond then show message and continue to next

    Else
     WScript.Echo(strComputer &amp; &quot;: Not responding...&quot;)
        objRecordSet.MoveNext
    End If
Loop
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
