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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 =
"name,ADsPath,description,member,sAMAccountName,DisplayName,EmployeeID,userAccountControl,mail,distinguishedName"
sProperties = sProperties &
",givenName,legacyExchangeDN,physicalDeliveryOfficeName,proxyAddresses,sn,birthLocation"
sProperties = sProperties &
",userPassword,unicodePwd,userPrincipalName,accountNameHistory"
If Trim(tAccount.Text) <> "" Then
sGroup = tAccount.Text
Else
sGroup = "*"
End If

oCmd.CommandText = "<" & sDomainADsPath &
">;(&(objectCategory=user)(sAMAccountName=" & sGroup & "));" & sProperties &
";subtree"
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
 
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

http://pbbergs.dynu.com/windows/windows.htm
 
Back
Top