我正在尝试从 Active Directory 中查询 userAccountControl 并将其与我在脚本中设置的字典进行匹配。
首先,我设置我的字典对象并填充它:
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 & Not Required"
uac.add "66082", "Disabled, Password Doesn't Expire & 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 & Not Required"
uac.add "328226", "Disabled, Smartcard Required, Password Doesn't Expire & Not Required"
然后我连接到我的 Active Directory 来查询它:
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"
然后我像这样遍历结果:
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
这一切都很好。我现在要做的是查询我使用来自 objRS("userAccountControl") 的结果创建的 uac 字典。当我尝试这样做时,它返回一个空白值?
set uacResult = objRS("userAccountControl")
Response.Write uac.Item(uacResult)
Response.Write " (" & uacResult & ")"
我很难过 - objRS 值是作为字符串返回的吗?如果我执行 Response.Write uac.Item("512") 它可以工作,但如果我执行 Response.Write uac.Item(uacResult) 则不行
有任何想法吗?