Note that there are some explanatory texts on larger screens.

plurals
  1. POASP: Reading Scripting.Dictionary with ADODB.Command Result
    text
    copied!<p>I'm trying to query the userAccountControl from Active Directory and match it against a dictionary that I've set up in my script.</p> <p>First of all I set up my dictionary object and fill it:</p> <pre><code>dim uac Set uac=Server.CreateObject("Scripting.Dictionary") uac.add "512", "Enabled Account" uac.add "514", "Disabled Account" uac.add "544", "Enabled, Password Not Required" uac.add "546", "Disabled, Password Not Required" uac.add "66048", "Enabled, Password Doesn't Expire" uac.add "66050", "Disabled, Password Doesn't Expire" uac.add "66080", "Enabled, Password Doesn't Expire &amp; Not Required" uac.add "66082", "Disabled, Password Doesn't Expire &amp; Not Required" uac.add "262656", "Enabled, Smartcard Required" uac.add "262658", "Disabled, Smartcard Required" uac.add "262688", "Enabled, Smartcard Required, Password Not Required" uac.add "262690", "Disabled, Smartcard Required, Password Not Required" uac.add "328192", "Enabled, Smartcard Required, Password Doesn't Expire" uac.add "328194", "Disabled, Smartcard Required, Password Doesn't Expire" uac.add "328224", "Enabled, Smartcard Required, Password Doesn't Expire &amp; Not Required" uac.add "328226", "Disabled, Smartcard Required, Password Doesn't Expire &amp; Not Required" </code></pre> <p>Then I connect to my Active Directory to query it:</p> <pre><code>Set objDomain = GetObject ("GC://RootDSE") objADsPath = objDomain.Get("defaultNamingContext") Set objDomain = Nothing Set objConn = Server.CreateObject("ADODB.Connection") objConn.provider ="ADsDSOObject" objConn.Properties("User ID") = "domain\administrator" objConn.Properties("Password") = "password" objConn.Properties("Encrypt Password") = True objConn.open "Active Directory Provider" Set objCom = CreateObject("ADODB.Command") Set objCom.ActiveConnection = objConn objCom.CommandText ="select name,userAccountControl FROM 'GC://"+objADsPath+"' where sAMAccountname='*' and objectCategory='user' and objectCategory='person' ORDER by sAMAccountname" </code></pre> <p>Then I loop through the results like so:</p> <pre><code>Set objRS = objCom.Execute Do While Not objRS.EOF Or objRS.BOF Response.Write objRS("name") set uacResult = objRS("userAccountControl") objRS.MoveNext Response.Flush Loop objRS.Close objConn.Close Set objRS = Nothing Set objConn = Nothing Set objCom = Nothing Set objADsPath = Nothing Set objDomain = Nothing </code></pre> <p>This all works absolutely fine. What I want to do now is to query the uac dictionary that I created using the result from objRS("userAccountControl"). When I try to do that, it returns a blank value?</p> <pre><code>set uacResult = objRS("userAccountControl") Response.Write uac.Item(uacResult) Response.Write " (" &amp; uacResult &amp; ")" </code></pre> <p>I'm stumped - is the objRS value returned as a string?? It works if I do Response.Write uac.Item("512") but not if I do Response.Write uac.Item(uacResult)</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload