From: Francois Lafont on 9 Sep 2010 18:32 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 9 Sep 2010 22:32 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 10 Sep 2010 16:30 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 10 Sep 2010 16:50 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 10 Sep 2010 17:26 "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() '###############################
|
Next
|
Last
Pages: 1 2 Prev: match computers in 2 text files Next: Move printers from win2003 cluster to win2008 cluster |