Re: Get ADsPath W2K user



Hello Richard,

Unfortunately this still does not work. I'm beginning to think that this
problem is nog related to the scipt itself, but something else. Anyway, when
I run the script in which I have adapted according to your suggestions, I
receive the following error:

"A referral was returned from the server"

The source provide in this case is 'provider', and the error code is
8007202B. Also, I pasted the code of the script below.

strUserName = "testuser"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText =
"<LDAP://dc=testdomain,dc=local>;(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & strUserName & "));AdsPath;subtree"

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.eof
strField = objRecordSet.Fields("AdsPath")
WScript.Echo strField
objRecordSet.MoveNext
Loop

objConnection.Close

Any suggestions?


"Richard Mueller [MVP]" wrote:

First, remove "On Error Resume Next" in case this is masking an error
message that could help troubleshoot. There is no need to disable normal
error handling. Next, I would use:

"(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & strUserName
& "))"

In fact, since sAMAccountName must be unique in the domain, you should be
able to use:

"(sAMAccountName=" & strUserName & ")"

Finally, remove the space after AdsPath where you retrieve the value. It
should be:

strField = objRecordSet.Fields("AdsPath")

Otherwise, the code looks good and should work the same on W2k and W2k3.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Richard W" <RichardW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1F22D756-A0EF-4213-94CB-4FE5564CFF5B@xxxxxxxxxxxxxxxx
Hello all,

I am trying to search a Windows 2000 domain for users, and then get back
the
AdsPath, for example cn=testuser,ou=accounts,dc=testdomain,dc=local. I
have a
piece of code that already successfully used in a Windows Server 2003
domain,
but when I try this script in a Windows 2000 domain I receive the error:

“A referral was returned from the server”

The script contains the following code:

On Error Resume Next
strUserName = "testuser"
dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=testdomain,dc=local>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));AdsPath;subtree"

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.eof
strField = objRecordSet.Fields("AdsPath ")
WScript.Echo strField
objRecordSet.MoveNext
Loop

objConnection.Close

Does anybody know what’s the problem here? Or is there maybe a different
way
I can search a Windows 2000 domain based on accountname, and which
returnes
the AdsPath or CN?

Many thanks in advance.

Regards,
Richard




.



Relevant Pages

  • Re: Get ADsPath W2K user
    ... I am trying to search a Windows 2000 domain for users, ... The script contains the following code: ... Set objConnection = CreateObject ... strField = objRecordSet.Fields ...
    (microsoft.public.scripting.vbscript)
  • [Q] WMI where ... like statement
    ... I wanted to get a list of all machines running a windows OS. ... Const ADS_SCOPE_SUBTREE = 2 ... Set objConnection = CreateObject ... If I cut the like part out of the script all works fine. ...
    (microsoft.public.windows.server.general)
  • AD users manage
    ... In a windows 2003 domain I need manage AD users by vb script. ... dtStart = TimeValue) ... Set objConnection = CreateObject ...
    (microsoft.public.windows.server.scripting)
  • Re: Microsoft Warns of New Windows Flaw (March 19, 2003 )
    ... In WINDOWS SETUP in ADD/REMOVE PROGRAMS of Control Panel ... Uninstall Outlook Express, ... Java, Javascript, ActiveX and all the other script runner toys Billy ... Install WebWasher the spammers are terrified of free from ...
    (comp.security.misc)
  • Re: Microsoft Warns of New Windows Flaw (March 19, 2003 )
    ... In WINDOWS SETUP in ADD/REMOVE PROGRAMS of Control Panel ... Uninstall Outlook Express, ... Java, Javascript, ActiveX and all the other script runner toys Billy ... Install WebWasher the spammers are terrified of free from ...
    (comp.security.firewalls)