check for valid domain
3
check if a string is a valid domain ex.: dsc-services.be
Function isDomain(strInput)
Dim domainSplit, domainName, objRecordSet, test
On Error Resume Next
domainSplit = split(strInput, ".")
domainName = ""
For Each domainPart In domainSplit
domainName = domainName & "DC=" & domainPart & ","
Next
domainName = Left(domainName, Len(domainName) - 1)
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, Location from 'LDAP://" & domainName & "' where objectClass='computer'"
objCommand.Properties("Timeout") = 3
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
If Err.Number <> 0 Then
isDomain = False
Else
isDomain = True
End If
End Function






There are currently no comments for this snippet.