lafafmentvotre Posted May 25, 2009 Share Posted May 25, 2009 (edited) Hello everbody First, sorry for my bad english. I need a script to ask LDAP with a combobox. I want a combo where i write the begin name and after click on search button, the combobox purpose users who begin with the first characters. Is it possible ? Someone have example ? Thanks by advance Edited May 25, 2009 by lafafmentvotre Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2009 Developers Share Posted May 25, 2009 This is an portion of a script I wrote a few years ago and does a Search in the AD for a Useraccount. Might give you an idea to work from : $l_UserId = "a"; begin of username Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<LDAP://dc=mydomain,dc=Comp,dc=Inc>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & $l_UserId & "*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties("Page Size") = 100 $objCommand.Properties("Timeout") = 30 $objCommand.Properties("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF $strName = $objRecordSet.Fields("sAMAccountName" ).Value $strCN = $objRecordSet.Fields("cn" ).value $strdisplayName = $objRecordSet.Fields("displayName" ).value $strSN = $objRecordSet.Fields("SN" ).value $strdistinguishedName = $objRecordSet.Fields("distinguishedName" ).value ; Update your Combo control GUICtrlsetdata($h_Combo, $strName & "|" & $strCN & "|" & $strdistinguishedName, $h_LV) $objRecordSet.MoveNext WEnd $objConnection.Close SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 25, 2009 Author Share Posted May 25, 2009 Hello Thanks for response. What is the $h_LV variable ? Thanks Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2009 Developers Share Posted May 25, 2009 HelloThanks for response.What is the $h_LV variable ?ThanksYou will have to make that line of code correct for your needs on how your GUI and Combo needs to be filled. Like I said, this piece of code is from a larger script.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 25, 2009 Author Share Posted May 25, 2009 Ok Thanks a lot, i test it tomorow morning Good evening Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 26, 2009 Author Share Posted May 26, 2009 Hello It's ok but now, how can i automatically refresh my combobox(sAMAccountName) and my label(mail) without clicking on "Search/Refresh" button. Here is my code Thanks for help expandcollapse popup;################################################################### ;AutoIT Variables #include <GUIConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <ComboConstants.au3> ;################################################################### ;Script Variables $version="V1.0" $strDomain = "my domain" $GUI = GUICreate("Password Generator", 420, 395, -1, -1, $WS_POPUPWINDOW) $m1 = "------ "& StringTrimRight(@ScriptName,4) & " "& $version &" ------" $Title = GUICtrlCreateLabel($m1, 20, 10, 390, 20, $SS_CENTER) GUICtrlSetFont(-1, 9, 800) $Label_1 = GUICtrlCreateLabel("User_Password", 89, 35, 100, 15, $SS_RIGHT) $Input_1 = GUICtrlCreateInput("", 120, 50, 70, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY+$ES_CENTER)) GUICtrlSetFont(-1, 9, 800) $Label_2 = GUICtrlCreateLabel("Manager_Password", 222, 35, 100, 15,$SS_LEFT) $Input_2 = GUICtrlCreateInput("", 230, 50, 70, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY+$ES_CENTER)) GUICtrlSetFont(-1, 9, 800) $Label_3 = GUICtrlCreateLabel("Password", 185, 85, 50, 15, $SS_CENTER) $Input_3 = GUICtrlCreateInput("", 163, 100, 100, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY+$ES_CENTER)) GUICtrlSetFont(-1, 9, 800) $Label_4 = GUICtrlCreateLabel("Special chars include in the pass :", 10, 135) $Checkbox_1 = GUICtrlCreateCheckbox("!", 60, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_2 = GUICtrlCreateCheckbox("%", 100, 150) GUICtrlSetState(-1,$GUI_DISABLE+$GUI_CHECKED) $Checkbox_3 = GUICtrlCreateCheckbox("-", 140, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_4 = GUICtrlCreateCheckbox("]", 180, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_5 = GUICtrlCreateCheckbox("#", 220, 150) GUICtrlSetState(-1,$GUI_DISABLE+$GUI_CHECKED) $Checkbox_6 = GUICtrlCreateCheckbox("(", 260, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_7 = GUICtrlCreateCheckbox("+", 300, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_8 = GUICtrlCreateCheckbox("/", 340, 150) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_9 = GUICtrlCreateCheckbox("@", 60, 170) GUICtrlSetState(-1,$GUI_DISABLE+$GUI_CHECKED) $Checkbox_10 = GUICtrlCreateCheckbox("*", 100, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_11 = GUICtrlCreateCheckbox("=", 140, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_12 = GUICtrlCreateCheckbox("\", 180, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_13 = GUICtrlCreateCheckbox("$", 220, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_14 = GUICtrlCreateCheckbox(")", 260, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_15 = GUICtrlCreateCheckbox("[", 300, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Checkbox_16 = GUICtrlCreateCheckbox("?", 340, 170) GUICtrlSetState(-1,$GUI_DISABLE) $Generate = GUICtrlCreateButton("Generate_Pass", 15, 351, 90, 30) $Copy = GUICtrlCreateButton("Copy_Pass", 115, 351, 90, 30) $SendAll=GuictrlCreateButton("Send_Pass", 215, 351, 90, 30) $Exit = GuictrlCreateButton("Exit", 315, 351, 90, 30) $Label_4 = GUICtrlCreateLabel("User : ", 10, 205, 90, 15,$SS_RIGHT) $UserCombo = GUICtrlCreateCombo("", 100, 200, 200, 20) ;~ GUICtrlSetFont(-1, 9, 800) $SearchUser=GUICtrlCreateButton("Search/Refresh", 305, 200, 90, 20) $Label_5=GUICtrlCreateLabel("User_eMail : ", 10, 230, 90, 15,$SS_RIGHT) $Label_6=GUICtrlCreateInput("",100, 227, 200,20,BitOR($ES_AUTOHSCROLL,$ES_READONLY)) $Label_7 = GUICtrlCreateLabel("Manager : ", 10, 265, 90, 15,$SS_RIGHT) $ManagerCombo = GUICtrlCreateCombo("", 100, 260, 200, 20) ;~ GUICtrlSetFont(-1, 9, 800) $SearchManager=GUICtrlCreateButton("Search/Refresh", 305, 260, 90, 20) $Label_8=GUICtrlCreateLabel("Manager_eMail : ", 10, 290, 90, 15,$SS_RIGHT) $Label_9=GUICtrlCreateInput("",100, 287, 200,20,BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE or $nMsg=$Exit Exit Case $nMsg = $Generate $Read_Char = "8" _Randomize($Read_Char) Case $nMsg = $Copy $READ = GUICtrlRead($Input_3) ClipPut($READ) Case $nMsg=$SendAll Case $nMsg=$SearchUser _SearchUser($SearchUser) Case $nMsg=$SearchManager _SearchManager($SearchManager) EndSelect WEnd ;~ Func _SendPassword ;~ EndFunc Func _SearchUser($SearchUser) $UserId=GUICtrlRead($UserCombo) If $UserId="" Then MsgBox(48, "Infos User", "Merci de saisir des caractères avant de cliquer sur ""Search""", 5) Else Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<LDAP://DC=xxxx,DC=xxxx>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*" & $UserId & "*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName,mail" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties("Page Size") = 100 $objCommand.Properties("Timeout") = 30 $objCommand.Properties("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF $strName = $objRecordSet.Fields("sAMAccountName" ).Value $strCN = $objRecordSet.Fields("cn" ).value $strdisplayName = $objRecordSet.Fields("displayName" ).value $strSN = $objRecordSet.Fields("SN" ).value $strdistinguishedName = $objRecordSet.Fields("distinguishedName" ).value $strMail=$objRecordSet.Fields("mail" ).value GUICtrlsetdata($UserCombo, $strName) GUICtrlsetdata($Label_6, $strMail) $objRecordSet.MoveNext WEnd $objConnection.Close EndIf EndFunc Func _SearchManager($SearchManager) $ManagerId=GUICtrlRead($ManagerCombo) If $ManagerId="" Then MsgBox(48, "Infos Manager", "Merci de saisir des caractères avant de cliquer sur ""Search""", 5) Else Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<LDAP://DC=xxxx,DC=xxxx>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*" & $ManagerId & "*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName,mail" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties("Page Size") = 100 $objCommand.Properties("Timeout") = 30 $objCommand.Properties("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF $strName = $objRecordSet.Fields("sAMAccountName" ).Value $strCN = $objRecordSet.Fields("cn" ).value $strdisplayName = $objRecordSet.Fields("displayName" ).value $strSN = $objRecordSet.Fields("SN" ).value $strdistinguishedName = $objRecordSet.Fields("distinguishedName" ).value $strMail=$objRecordSet.Fields("mail" ).value GUICtrlsetdata($ManagerCombo, $strName) GUICtrlsetdata($Label_9, $strMail) $objRecordSet.MoveNext WEnd $objConnection.Close EndIf EndFunc Func _Randomize($Length) $AddSpecial = "@#%" $Array = StringSplit("ABCDEFGHJKLMNPQRSTUVWXYZ0123456789" & $AddSpecial,"") $Pass = "" For $X = 1 to $Length $Pass &= $Array[Random (1, $Array[0], 1)] Next $User_Pass=StringLeft($Pass,4) $Manager_Pass=StringRight($Pass,4) GUICtrlSetData($Input_1, $User_Pass) GUICtrlSetData($Input_2, $Manager_Pass) GUICtrlSetData($Input_3, $Pass) Return $Pass EndFunc Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 26, 2009 Author Share Posted May 26, 2009 Hello Someone can help me please ? Thank you Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 26, 2009 Author Share Posted May 26, 2009 Hello Nobody for help ? Thanks Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2009 Developers Share Posted May 26, 2009 Your question is not clear to me and as I cannot test your script its hard to figure out what you could mean. Maybe try explaining it in more detail. ps. please be little more patient on the thread bumping or did we promise you another SLA when you signed the contract? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 26, 2009 Author Share Posted May 26, 2009 Hello It's hard for me to explain in english, but : At present, i ask ldap with function :_SearchUseroÝ÷ Ûh®éðØ[ºÛh«¢+ØÀÌØíMÉ¡UÍÈoÝ÷ Ù8^r¡º1jëh×6$UserCombo = GUICtrlCreateCombo("", 100, 200, 200, 20)oÝ÷ Ù©Ýjëh×6$Label_6 are refresh with these results. But i must click on button $SeachUser to refresh data when i change the combobox result (for ver change i made) I search a solution (like a loop) who refresh data when i wrote something (characters) in the combobox $UserCombo... Is it clear like this ? I'm sorry for my english Jos. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2009 Developers Share Posted May 26, 2009 (edited) If you want to start an action when you select a new value in the Combobox you need to test for that Controlhandle and perform an action. e.g.: Case $nMsg = $UserCombo _SearchUser(GUICtrlRead($UserCombo )) Edited May 26, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
lafafmentvotre Posted May 27, 2009 Author Share Posted May 27, 2009 HelloThanks for response but it doesn't work.Is it possible to do that like the search of this site : Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now