check for valid domain





3
Date Submitted Thu. Mar. 2nd, 2006 4:21 AM
Revision 1 of 1
Syntax Master dannyboy
Tags DOMAIN | valid | VBSCRIPT
Comments 0 comments
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
 

Comments

There are currently no comments for this snippet.

Voting