How to get the AD User Information by VB and program not in Domain



Have to write a VB program to get the main domain AD User Information,process
and Auth.
But this program not in the main AD domain.
Already check some documents to write the connection parameter , but it
never work.
The Code is bellow: But the error happen in "oCmd.Execute"
The Error Message is "The Data Table is not exist"
The code run in domain is ok.
Dim oRootDSE, oCon, oCmd, oRecordSet
Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
Dim aDescription, aMember, iCount, intUAC
On Error GoTo ErrorHandle
sDomainADsPath = "LDAP://DC=" & Replace(tDomain.Text, ".", ",DC=")
Set oCon = CreateObject("ADODB.Connection")
'oCon.Provider = "ADsDSOObject"
oCon.Open "Provider=ADSDSOObject;User Id=ABC;Password=XXX;"
Set oCmd = CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

DOMAIN = "LDAP://dc=" & tDomain.Text & ", dc=domainextension"
sql = "select cn,distinguishedname from '" + sDomainADsPath + "' where
objectclass='" + tAccount.Text + "' and objectclass<>'computer'"
oCmd.CommandText = sql
Set oRecordSet = oCmd.Execute

sProperties =
sProperties = sProperties &
sProperties = sProperties &
If Trim(tAccount.Text) <> "" Then
sGroup = tAccount.Text
sGroup = "*"
End If

oCmd.CommandText = "<" & sDomainADsPath &
">;(&(objectCategory=user)(sAMAccountName=" & sGroup & "));" & sProperties &
oCmd.Properties("Page Size") = 100

Set oRecordSet = oCmd.Execute
I don't know is it suitable to post this question here,
but pls comment how it work out. Thanks

Paul Bergson

If you want a program that will list out details on all users try the link
below. It needs no details of the domain nor any user id's or passwords.
It should be easily amendable.

This download will provide ALL user ids from your domain in a csv file
stored at c:\temp,
which is modifiable via the const def'n FileLocation. The script will
determine all parameters
about your AD, modifications to add or remove parameters should be
realtively easy
Attributes include:
a.. User Name
b.. Last Logon Date
c.. Creation Date
d.. Home Folder
e.. Script
f.. Display Name
g.. Password Not Needed
h.. Password Does Not Expire
i.. Expired Password
j.. Account Is Disabled

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question