Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am having 2 AD. While running my script I will be providing userid to one of the AD and getting the required user data. Then using all that data, I will be creating new user in other AD.

If I run my script from same AD itself then it is working fine but when I am running it from some another machine in different domain then it is problem. It's giving error as "access denied".

To check the access I shared one folder on AD and tried accessing it from command prompt. That folder was accessible.

Below is part of my script which is giving problem
VB
strNTName = "abcd"
strDNSDomain = "DC=AD,DC=COM"
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Properties("User ID") = "abcd"
adoConnection.Properties("Password") = "abcd_wxyz"
'adoConnection.Properties("Encrypt Password") = TRUE
'adoConnection.Properties("ADSI Flag") = 3

'adoConnection.Open
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Search for all users.
strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strNTName & "))"
' Comma delimited list of attribute values to retrieve.
'strAttributes = "givenName,sn,mail,userPrincipalName"
strAttributes = "givenName,sn"
' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
MsgBox adoRecordset.RecordCount


Can anyone please help to solve this problem?
Thanks in advance.
Posted
Updated 22-Jul-10 21:11pm
v2
Comments
Sandeep Mewara 23-Jul-10 3:11am    
Always use PRE tags to format code part. It makes the question readable.

1 solution

Most of the time the LDAP connection isn't okay. You could always try a public LDAP server for testing the code.

http://www.emailman.com/ldap/public.html[^]

http://www.keutel.de/directory/public_ldap_servers.html[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900