Specify the Username and Password on the DirectoryEntry object before trying to access it with the Searcher. Please consult the link below for detailed information from MSDN on how the credential process works.
It sounds like your having a problem with LDAP instead of authentication. Have you tested accessing LDAP manually to see if your port is being blocked or something else?
M.R.
Member
40 Points
23 Posts
Access Directory Services from a non domain-joined computer?
Feb 16, 2012 07:23 PM|LINK
Hello,
I have the following simple code that works perfectly from an AD-joined computer:
Dim sName As String = sUserID
Dim oRoot As DirectoryEntry = New DirectoryEntry
Dim oSearcher As DirectorySearcher = New DirectorySearcher
Dim oResults As SearchResultCollection
oRoot.Path = "LDAP://OU=Users,OU=Hgies,DC=rci,DC=youit,DC=ca"
oSearcher.SearchRoot = oRoot
oSearcher.Filter = "(&(objectclass=User)(objectCategory=person)(sAMAccountName=" & sName & "))"
oResults = oSearcher.FindAll() ----------- error here if ran from a non-AD joined computer
However, when I run it from a non-AD computer I experience the following error on the last line (in bold):
The specified domain either does not exist or could not be contacted.
I tried to include credentials, something like:
oRoot.Username = "domain\username"
oRoot.Password = "******"
but it does not make any difference…
Please advise,
Regards,
M.R.
N_EvilScott
Star
8325 Points
1494 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 07:37 PM|LINK
Specify the Username and Password on the DirectoryEntry object before trying to access it with the Searcher. Please consult the link below for detailed information from MSDN on how the credential process works.
http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.username.aspx
M.R.
Member
40 Points
23 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:08 PM|LINK
Thank you for the link Scott.
N_EvilScott
Star
8325 Points
1494 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:12 PM|LINK
You need to pass in the Entry as an overload for the Searcher:
M.R.
Member
40 Points
23 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:31 PM|LINK
Thank you very much Scott for your detailed answer. I revised my code as directed and tested it an an AD-joined computer (worked fine):
Dim oRoot As DirectoryEntry = New DirectoryEntry
Dim oResults As SearchResultCollection
oRoot.Username = "domain\username"
oRoot.Password = "*****"
oRoot.Path = "LDAP://OU=Users,OU=FeiY,DC=rci,DC=Oigj,DC=ca"
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
oSearcher.Filter = "(&(objectclass=User)(objectCategory=person)(sAMAccountName=" & sName & "))"
oResults = oSearcher.FindAll() --- still experiencing an error on non-AD joined computer
Unfortunately I am having the same error when ran it from the non-AD computer...(The specified domain either does not exist or could not be contacted)
Regards,
M.R.
N_EvilScott
Star
8325 Points
1494 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:32 PM|LINK
It sounds like your having a problem with LDAP instead of authentication. Have you tested accessing LDAP manually to see if your port is being blocked or something else?
M.R.
Member
40 Points
23 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:33 PM|LINK
I must also mention that the non-AD computer is a Windows Server 2008 R2 and I am developing in VS 2010 (an ASP.Net application)
Thanks,
M.R.
M.R.
Member
40 Points
23 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:34 PM|LINK
Not yet but this is very good ideea.
thanks,
M.R.
N_EvilScott
Star
8325 Points
1494 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:34 PM|LINK
Are you on the same network? Or are you accessing it through a VPN or some other means?
M.R.
Member
40 Points
23 Posts
Re: Access Directory Services from a non domain-joined computer?
Feb 16, 2012 08:36 PM|LINK
Yes I am on the same network, I can browse computers and access shared folders.