我有一个连接到AD并查询LDAP的脚本。只要您拥有正确的凭据并连接到AD,该脚本就可以正常工作。这个脚本与各种子程序一起运行,我试图使脚本更健壮,以便能够在多个可能没有AD的环境中运行。
On Error Resume Next
Dim tempResult
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.CommandTimeout = 10
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on user objects.
strFilter = ""
' Comma delimited list of attribute values to retrieve.
strAttributes = "comment,c,co,countryCode,department,description,directReports,displayName,distinguishedName,info,lastLogon,lastLogonTimestamp,mail,manager,memberOf,msExchHomeServerName,name,objectCategory,objectClass,operatingSystem,operatingSystemServicePack,operatingSystemVersion,ou,pwdLastSet,sAMAccountName,title,userAccountControl,userPrincipalName"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
if Err<>0 Then
'log error information
End If
Err.Clear
On Error GoTo 0
但是,当我将脚本包含在On Error Resume Next中时,脚本将在未连接到AD的计算机上运行或在AD上没有足够的权限时挂起。如果出现错误,任何能够使这部分脚本运行并继续的想法?再次,如果有错误我不关心得到任何结果我只是希望脚本继续它的快乐方式。