From: Francois Lafont on
Hi,

I don't understand this code below :

> cscript //nologo MyScript.vbs
USER DOES'NT EXIST

But the user exsits, I can see it with Active Directory and the
sAMAccountName is good ?



'------------------------------------------------
Const adPosEOF = -3

Set objConnection = Wscript.CreateObject("ADODB.Connection")
Call objConnection.Open ("Provider=ADsDSOObject;")
Set objCommand = Wscript.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" _
& ">;(ObjectCategory=user);sAMAccountName;subtree"


Set objRecord = objCommand.Execute

Call objRecord.MoveFirst()
Call objRecord.find("sAMAccountName='traore-ma'")

If objRecord.AbsolutePosition = adPosEOF Then
Wscript.Echo "USER EXISTS"
Else
Wscript.Echo "USER DOES'NT EXIST"
End If

Call objRecord.Close()
Call objConnection.Close()
'------------------------------------------------
From: ekkehard.horner on
Francois Lafont schrieb:
> Hi,
>
> I don't understand this code below :
>
>> cscript //nologo MyScript.vbs
> USER DOES'NT EXIST
>
> But the user exsits, I can see it with Active Directory and the
> sAMAccountName is good ?
>
>
>
> '------------------------------------------------
> Const adPosEOF = -3
>
> Set objConnection = Wscript.CreateObject("ADODB.Connection")
> Call objConnection.Open ("Provider=ADsDSOObject;")
> Set objCommand = Wscript.CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
> objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" _
> & ">;(ObjectCategory=user);sAMAccountName;subtree"
>
>
> Set objRecord = objCommand.Execute
>
> Call objRecord.MoveFirst()
> Call objRecord.find("sAMAccountName='traore-ma'")
>
> If objRecord.AbsolutePosition = adPosEOF Then

If the position is EOF then the .find failed

> Wscript.Echo "USER EXISTS"
> Else

If the position is *not* EOF then the .find succeeded

> Wscript.Echo "USER DOES'NT EXIST"
> End If
>
> Call objRecord.Close()
> Call objConnection.Close()
> '------------------------------------------------

From: Francois Lafont on
Le 10/09/2010 04:32, ekkehard.horner wrote :

> If the position is EOF then the .find failed
>
>> Wscript.Echo "USER EXISTS"
>> Else
>
> If the position is *not* EOF then the .find succeeded
>
>> Wscript.Echo "USER DOES'NT EXIST"
>> End If

Oops, sorry it's a mistake I made when I tried to copy and simplify my
code in my message. But, alas, I have a *reall* problem of user
research. This time, I show a good example of my problem.

> cscript //nologo MyScript
USER DOESN'T EXIST

whereas the user exists :

1) I can see him in Active Directory

2) With LDAP Browser, I can see :

* distinguishedName :
CN=traore-ma2,OU=2E,OU=Eleves,OU=Profs-Eleves,OU=Utilisateurs,DC=yourcenar,DC=local

* sAMAccountName : traore-ma2

Here is the good example of my problematic script (I hope :-)) :

'###############################
Const adPosEOF = -3

Set objConnection = Wscript.CreateObject("ADODB.Connection")
Call objConnection.Open ("Provider=ADsDSOObject;")
Set objCommand = Wscript.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" & _
">;(ObjectCategory=user);sAMAccountName;subtree"
Set objRecord = objCommand.Execute

Call objRecord.MoveFirst()
Call objRecord.find("sAMAccountName='traore-ma2'")

If objRecord.AbsolutePosition = adPosEOF Then
Wscript.Echo "USER DOESN'T EXIST"
Else
Wscript.Echo "USER EXISTS"
End If

Call objRecord.Close()
Call objConnection.Close()
'###############################

It's curious, I have another user too with the sAMAccountName
"traore-ma" who is well detected by the script above. But why is
"traore-ma2" not detected ?

I'm quite upset because I use the .find method in a very important way
in a usefull script for me.

Thanks in advance for your help.

From: Francois Lafont on
I have just found a curious and perhaps important element. If I change
and I precise my research in the OU of the user "traore-ma2", the script
detects the user.

A) The concerned user is :

* distinguishedName :
CN=traore-ma2,OU=2E,OU=Eleves,OU=Profs-Eleves,OU=Utilisateurs,DC=yourcenar,DC=local

* sAMAccountName : traore-ma2


B) With this code :

'###############################
Const adPosEOF = -3

Set objConnection = Wscript.CreateObject("ADODB.Connection")
Call objConnection.Open ("Provider=ADsDSOObject;")
Set objCommand = Wscript.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

'<<<<<<<<<<<<<<THE CHANGE<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" & _
">;(ObjectCategory=user);sAMAccountName;subtree"
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Set objRecord = objCommand.Execute

Call objRecord.MoveFirst()
Call objRecord.find("sAMAccountName='traore-ma2'")

If objRecord.AbsolutePosition = adPosEOF Then
Wscript.Echo "USER DOESN'T EXIST"
Else
Wscript.Echo "USER EXISTS"
End If

Call objRecord.Close()
Call objConnection.Close()
'###############################

The user IS NOT detected.


C) With this code :

'###############################
Const adPosEOF = -3

Set objConnection = Wscript.CreateObject("ADODB.Connection")
Call objConnection.Open ("Provider=ADsDSOObject;")
Set objCommand = Wscript.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

'<<<<<<<<<<<<<<THE CHANGE<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
objCommand.CommandText =
"<LDAP://OU=2E,OU=Eleves,OU=Profs-Eleves,OU=Utilisateurs,DC=yourcenar,DC=local"
& _
">;(ObjectCategory=user);sAMAccountName;subtree"
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Set objRecord = objCommand.Execute

Call objRecord.MoveFirst()
Call objRecord.find("sAMAccountName='traore-ma2'")

If objRecord.AbsolutePosition = adPosEOF Then
Wscript.Echo "USER DOESN'T EXIST"
Else
Wscript.Echo "USER EXISTS"
End If

Call objRecord.Close()
Call objConnection.Close()
'###############################

The user IS detected !?!?

I execute my script on Windows Server 2000.


--
Fran�ois Lafont
From: James Whitlow on
"Francois Lafont" <francois(a)nospam.invalid> wrote in message
news:%23CVqQcSULHA.2064(a)TK2MSFTNGP05.phx.gbl...
> Le 10/09/2010 04:32, ekkehard.horner wrote :
>
>> If the position is EOF then the .find failed
>>
>>> Wscript.Echo "USER EXISTS"
>>> Else
>>
>> If the position is *not* EOF then the .find succeeded
>>
>>> Wscript.Echo "USER DOES'NT EXIST"
>>> End If
>
> Oops, sorry it's a mistake I made when I tried to copy and simplify my
> code in my message. But, alas, I have a *reall* problem of user
> research. This time, I show a good example of my problem.
>
>> cscript //nologo MyScript
> USER DOESN'T EXIST
>
> whereas the user exists :
>
> 1) I can see him in Active Directory
>
> 2) With LDAP Browser, I can see :
>
> * distinguishedName :
> CN=traore-ma2,OU=2E,OU=Eleves,OU=Profs-Eleves,OU=Utilisateurs,DC=yourcenar,DC=local
>
> * sAMAccountName : traore-ma2
>
> Here is the good example of my problematic script (I hope :-)) :
>
> '###############################
> Const adPosEOF = -3
>
> Set objConnection = Wscript.CreateObject("ADODB.Connection")
> Call objConnection.Open ("Provider=ADsDSOObject;")
> Set objCommand = Wscript.CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
> objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" & _
> ">;(ObjectCategory=user);sAMAccountName;subtree"
> Set objRecord = objCommand.Execute
>
> Call objRecord.MoveFirst()
> Call objRecord.find("sAMAccountName='traore-ma2'")
>
> If objRecord.AbsolutePosition = adPosEOF Then
> Wscript.Echo "USER DOESN'T EXIST"
> Else
> Wscript.Echo "USER EXISTS"
> End If
>
> Call objRecord.Close()
> Call objConnection.Close()
> '###############################
>
> It's curious, I have another user too with the sAMAccountName
> "traore-ma" who is well detected by the script above. But why is
> "traore-ma2" not detected ?
>
> I'm quite upset because I use the .find method in a very important way
> in a usefull script for me.
>
> Thanks in advance for your help.

Try adding the line:

objCommand.Properties("Page Size") = 999

...right after the 'objCommand.ActiveConnection = objConnection' line:

'###############################
Const adPosEOF = -3

Set objConnection = Wscript.CreateObject("ADODB.Connection")
Call objConnection.Open ("Provider=ADsDSOObject;")
Set objCommand = Wscript.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 999 '<*> This is the new line <*>
objCommand.CommandText = "<LDAP://DC=yourcenar,DC=local" & _
">;(ObjectCategory=user);sAMAccountName;subtree"
Set objRecord = objCommand.Execute

Call objRecord.MoveFirst()
Call objRecord.find("sAMAccountName='traore-ma2'")

If objRecord.AbsolutePosition = adPosEOF Then
Wscript.Echo "USER DOESN'T EXIST"
Else
Wscript.Echo "USER EXISTS"
End If

Call objRecord.Close()
Call objConnection.Close()
'###############################