<?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>Indented! &#187; userAccountControl</title>
	<atom:link href="http://www.indented.co.uk/index.php/tag/useraccountcontrol/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indented.co.uk</link>
	<description></description>
	<lastBuildDate>Mon, 17 Oct 2011 19:03:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Auditing userAccountControl with VbScript</title>
		<link>http://www.indented.co.uk/index.php/2008/10/22/auditing-useraccountcontrol/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/22/auditing-useraccountcontrol/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 19:23:51 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[userAccountControl]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=444</guid>
		<description><![CDATA[This VbScript searches the current domain for all users with &#8220;User cannot change password&#8221;, &#8220;Password never expires&#8221;, or &#8220;Trusted for delegation&#8221; set, the results of the search are written to a tab delimited text file. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This VbScript searches the current domain for all users with &#8220;User cannot change password&#8221;, &#8220;Password never expires&#8221;, or &#8220;Trusted for delegation&#8221; set, the results of the search are written to a tab delimited text file.<br />
<span id="more-444"></span></p>
<pre class="brush: vb; title: ; notranslate">
' UserAccountControl.vbs
'
' Script to report User Account Control Flag usage within the current domain.
'
' Author: Chris Dent
' Modified: 06/03/2008

Option Explicit

Const REPORT_FILE = &quot;Users.txt&quot;

' userAccountControl flag values
Const ADS_UF_PASSWD_CANT_CHANGE = &amp;H40
Const ADS_UF_DONT_EXPIRE_PASSWD = &amp;H10000
Const ADS_UF_TRUSTED_FOR_DELEGATION = &amp;H80000
Const ADS_SCOPE_SUBTREE = 2

Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &amp;H6
Const CHANGE_PASSWORD_GUID  = &quot;{ab721a53-1e2f-11d0-9819-00aa0040529b}&quot;

'
' Main Code
'

Dim objFileSystem, objFile, objConnection, objCommand
Dim objRootDSE, objRecordSet, objUser
Dim objSD, objDACL, objACE
Dim strPwdCantChange, strPwdDontExpire, strTrustedForDelegation
Dim strDisplayName, strUsername, strDN
Dim intUAC
Dim booList

' Create report file
Set objFileSystem = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFile = objFileSystem.OpenTextFile(REPORT_FILE, 2, True, 0)

' Write header
objFile.WriteLine &quot;Display Name&quot; &amp; VbTab &amp; &quot;Username&quot; &amp; VbTab &amp;_
  &quot;Distinguished Name&quot; &amp; VbTab &amp; &quot;Password Cannot Change&quot; &amp;_
  VbTab &amp; &quot;Password Never Expires&quot; &amp; VbTab &amp; &quot;Trusted for Delegation&quot;

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

Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
objCommand.ActiveConnection = objConnection

' Configure search
Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
objCommand.CommandText = &quot;SELECT displayName, distinguishedName, &quot; &amp;_
  &quot;sAMAccountName, userAccountControl, nTSecurityDescriptor FROM 'LDAP://&quot; &amp;_
  objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp;_
  &quot;' WHERE objectClass='user' AND objectCategory='person'&quot;
Set objRootDSE = Nothing

objCommand.Properties(&quot;Page Size&quot;) = 1000
objCommand.Properties(&quot;Timeout&quot;) = 600
objCommand.Properties(&quot;Searchscope&quot;) = ADS_SCOPE_SUBTREE
objCommand.Properties(&quot;Cache Results&quot;) = False
Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
  strPwdCantChange = &quot;False&quot; : strPwdDontExpire = &quot;False&quot;
  strTrustedForDelegation = &quot;False&quot;
  booList = False

  intUAC = objRecordSet.Fields(&quot;userAccountControl&quot;)

  ' Check for Password Cannot Change Flag

  Set objUser = GetObject(&quot;LDAP://&quot; &amp; objRecordSet.Fields(&quot;distinguishedName&quot;))
  Set objSD = objUser.Get(&quot;nTSecurityDescriptor&quot;)
  Set objDACL = objSD.DiscretionaryAcl

  For Each objACE in objDACL
    If objACE.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT And _
        LCase(objACE.ObjectType) = CHANGE_PASSWORD_GUID Then

      strPwdCantChange = &quot;True&quot; : booList = True
      Exit For
    End If
  Next

  Set objDACL = Nothing
  Set objSD = Nothing
  Set objUser = Nothing

  ' Check for password never expires

  If intUAC And ADS_UF_DONT_EXPIRE_PASSWD Then
    strPWDDontExpire = &quot;True&quot; : booList = True
  End If

  ' Check for trusted for delegation

  If intUAC And ADS_UF_TRUSTED_FOR_DELEGATION Then
    strTrustedForDelegation = &quot;True&quot; : booList = True
  End If

  If booList = True Then
    strDisplayName = objRecordSet.Fields(&quot;displayName&quot;)
    strUsername = objRecordSet.Fields(&quot;sAMAccountName&quot;)
    strDN = objRecordSet.Fields(&quot;distinguishedName&quot;)

    objFile.WriteLine strDisplayName &amp; VbTab &amp; strUsername &amp; VbTab &amp;_
    strDN &amp; VbTab &amp; strPwdCantChange &amp; VbTab &amp; strPwdDontExpire &amp;_
    VbTab &amp; strTrustedForDelegation
  End If

  objRecordSet.MoveNext
Wend

objConnection.Close

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
</pre>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/22/auditing-useraccountcontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

