jefhal Posted April 26, 2007 Share Posted April 26, 2007 This is what I get for trying to jump into someone else's code, but my code below is based entirely on ADTools.au3 that goes with ADFunctions.au3. ADTools runs perfectly on my domain. However, when I use my frankenstein revision of it, I get these errors ONLY WHEN the treeview item I choose has no LISTVIEW items in it. The code errors out at line 169: Return Here are the errors: 1. We intercepted a COM Error! Number is: 80005000. Windescription is: 2. Failed to retrieve AD object 3. We intercepted a COM Error! Number is: 80072030. There is no such object on the server 4. Failed to retrieve AD object Here's my code: expandcollapse popup#include <adfunctions.au3> #include <GuiConstants.au3> #include <array.au3> #Include <GuiTreeView.au3> #include <GuiList.au3> Dim $arrContainers, $ADToolGUI, $Treeview_Left, $Treeview_Right, $leftclass, $rightclass, $leftfqdn, $rightfqdn Dim $msg, $leftsam, $rightsam, $remuser, $adduser, $parent, $curritem, $str_ldap, $List_left, $List_Right, $currtreeitem, $fqdn, $class Dim $r_fqdn, $strCmdText, $dtrArray, $count, $HexNumber, $obj, $strQuery Dim $listbox, $button, $label, $i, $return Dim $objConnection, $objRootDSE, $objRecordSet, $arrContainers $LBS_EXTENDEDSEL = 0x800 Opt("GUIOnEventMode", 1) Opt("TrayIconDebug", 1) $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD $objCommand = ObjCreate("ADODB.Command") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") ; Open connection to AD $objCommand.ActiveConnection = $objConnection $objCommand.Properties ("Page Size") = 1000 $objCommand.Properties ("Searchscope") = 2 $objRootDSE = ObjGet("LDAP://RootDSE") Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name MsgBox(1,"$strDNSDomain",$strDNSDomain) $ADToolGUI = GUICreate("Active Directory Tool", 1000, 680) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") $Treeview_Left = GUICtrlCreateTreeView(10, 10, 200, 656, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER), $WS_EX_CLIENTEDGE) GUICtrlSetOnEvent($Treeview_Left, "UpdateTreeViewLeft") ;$List_left = GUICtrlCreateList("", 210, 10, 200, 675,$LBS_EXTENDEDSEL) $List_left = GUICtrlCreateList("", 210, 10, 200, 675, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL)) GUICtrlSetOnEvent($List_left, "UpdateAllBtns") $button = GUICtrlCreateButton("Get Selected", 420, 10, 260, 20) GUICtrlSetOnEvent($button, "GetSelectedNames") $Btn_GetProperties = GUICtrlCreateButton("Get Properties of Selected Objects", 420, 40, 260, 20) GUICtrlSetOnEvent($button, "GetProperties") ;~ $Btn_AddUsertoGroup = GUICtrlCreateButton("<--- Add User To Group --->", 420, 10, 160, 20) ;~ GUICtrlSetOnEvent($Btn_AddUsertoGroup, "AddUser") ;~ $Btn_RemoveUserFromGroup = GUICtrlCreateButton("<- Remove User From Group ->", 420, 40, 160, 20) ;~ GUICtrlSetOnEvent($Btn_RemoveUserFromGroup, "RemoveUser") ;~ $Btn_LeftUserMemberOf = GUICtrlCreateButton("<---Display Member Of", 420, 240, 130, 20) ;~ GUICtrlSetOnEvent($Btn_LeftUserMemberOf, "LeftUserMemberOf") ;~ $Btn_LeftGroupMembers = GUICtrlCreateButton("<- Display Group Members", 420, 270, 130, 20) ;~ GUICtrlSetOnEvent($Btn_LeftGroupMembers, "LeftGroupMembers") ;~ $Btn_LeftCreateGroup = GUICtrlCreateButton("<---Create Group", 420, 300, 130, 20) ;~ GUICtrlSetOnEvent($Btn_LeftCreateGroup, "LeftCreateGroup") ;~ $Btn_LeftDeleteGroup = GUICtrlCreateButton("<---Delete Group", 420, 330, 130, 20) ;~ GUICtrlSetOnEvent($Btn_LeftDeleteGroup, "LeftDeleteGroup") ; Disable all buttons before displaying the GUI UpdateAllBtns() _ADGetObjectsInOU($arrContainers, $strDNSDomain, "ObjectClass='organizationalUnit'", 1, "name,ADsPath", "name") MsgBox(1,"Message 1", "Got past _ADGetObjectsInOU") For $i = 1 To $arrContainers[0][0] - 1 ;~ GUICtrlCreateTreeViewItem($arrContainers[$i][0], $Treeview_Right) ;~ GUICtrlSetOnEvent(-1, "UpdateTreeViewRight") GUICtrlCreateTreeViewItem($arrContainers[$i][0], $Treeview_Left) GUICtrlSetOnEvent(-1, "UpdateTreeViewLeft") Next GUISetState() Opt("GUIOnEventMode", 1) While 1 WEnd Exit Func UpdateTreeViewLeft() MsgBox(1,"Debug4","got to debug19") ;DisableAllBtns() ;MsgBox(1,"Debug1","got to debug1") $parent = GUICtrlRead($Treeview_Left) ;MsgBox(1,"Debug2","got to debug2") $curritem = $parent MsgBox(1,"$Treeview_left and $curritem",$Treeview_Left & @CRLF & $curritem) If BitAND(_GUICtrlTreeViewGetState($Treeview_Left, $curritem), 64) = 64 Then ;MsgBox(1,"Debug4","got to debug4 and bitand = 64") UpdateListLeft() MsgBox(1,"Debug18","got to debug18") Return EndIf $str_ldap = "" While GUICtrlRead(_GUICtrlTreeViewGetParentID($Treeview_Left, $curritem)) <> 0 $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," MsgBox(1,"$str_ldap",$str_ldap) $curritem = _GUICtrlTreeViewGetParentID($Treeview_Left, $curritem) WEnd $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," & $strDNSDomain _ADGetObjectsInOU ($arrContainers, $str_ldap, "ObjectClass='organizationalUnit'", 1, "name,ADsPath", "name") ;_ArrayDisplay($arrContainers,"$arrContainers") If $arrContainers <> 0 Then For $i = 1 To $arrContainers[0][0] $currtreeitem = GUICtrlCreateTreeViewItem($arrContainers[$i][0], @GUI_CtrlId) GUICtrlSetOnEvent($currtreeitem, "UpdateTreeViewLeft") Next EndIf _GUICtrlTreeViewExpand($Treeview_Left, 1, $parent) ;MsgBox(1,"Message 2","Got past _guictrltreeviewexpand in UpdateTreeViewLeft") UpdateListLeft() UpdateAllBtns() EndFunc ;==>UpdateTreeViewLeft Func UpdateListLeft() ;MsgBox(1,"Debug4","got to debug6") GUICtrlSetData($List_left, "") ;MsgBox(1,"Debug4","got to debug7") GUICtrlSetData($List_left, "|Refreshing List, please wait...") ;MsgBox(1,"Debug4","got to debug8") If GUICtrlRead($Treeview_Left) = 0 Then Return ;MsgBox(1,"Debug4","got to debug9") $parent = GUICtrlRead($Treeview_Left) $curritem = $parent $str_ldap = "" ;MsgBox(1,"Debug4","got to debug10") While GUICtrlRead(_GUICtrlTreeViewGetParentID($Treeview_Left, $curritem)) <> 0 $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," $curritem = _GUICtrlTreeViewGetParentID($Treeview_Left, $curritem) ;MsgBox(1,"Debug4","got to debug11") WEnd ;MsgBox(1,"Debug","got to debug12") $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," & $strDNSDomain MsgBox(1,"$str_ldap",$str_ldap) _ADGetObjectsInOU ($arrContainers, $str_ldap, "objectclass='user' OR objectclass = 'group' OR objectclass='computer'", 1, "cn", "cn") MsgBox(1,"Debug","got to debug14") If $arrContainers = 0 Then MsgBox(1,"Debug","got to debug15") GUICtrlSetData($List_left, "") MsgBox(1,"Debug","got to debug15a") Return <<<<<<<<<<<<<<<<<<<ERROR OCCURS HERE!!!!!!!!!>>>>>>>>>>>>>>>>>>>>>>> EndIf MsgBox(1,"Debug","got to debug16") GUICtrlSetData($List_left, "|" & _ArrayToString($arrContainers, "|", 1)) MsgBox(1,"Debug","got to debug17") EndFunc ;==>UpdateListLeft Func GetObjectTypeLeft() $fqdn = ReadFQDNFromGUILeft() If $fqdn = "" Then Return $objectsamid = _ADDNToSamAccountName ($fqdn) $class = _ADGetObjectClass ($objectsamid) Return $class EndFunc ;==>GetObjectTypeLeft Func ReadFQDNFromGUILeft() If GUICtrlRead($Treeview_Left) = 0 Then Return "" If GUICtrlRead($List_left) = "" Then Return "" $object = GUICtrlRead($List_left) $parent = GUICtrlRead($Treeview_Left) $curritem = $parent $str_ldap = "" While GUICtrlRead(_GUICtrlTreeViewGetParentID($Treeview_Left, $curritem)) <> 0 $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," $curritem = _GUICtrlTreeViewGetParentID($Treeview_Left, $curritem) WEnd $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," & $strDNSDomain If StringInStr($object, ",") Then $objarray = StringSplit($object, ",") MsgBox(1,"$object",$object) $object = "" For $i = 1 To $objarray[0] $object = $object & $objarray[$i] & "\," Next $object = StringTrimRight($object, 2) EndIf $r_fqdn = "CN=" & $object & "," & $str_ldap Return $r_fqdn EndFunc ;==>ReadFQDNFromGUILeft Func ReadOUFromGUILeft() If GUICtrlRead($Treeview_Left) = 0 Then Return "" If GUICtrlRead($List_left) = "" Then Return "" $object = GUICtrlRead($List_left) $parent = GUICtrlRead($Treeview_Left) $curritem = $parent $str_ldap = "" While GUICtrlRead(_GUICtrlTreeViewGetParentID($Treeview_Left, $curritem)) <> 0 $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," $curritem = _GUICtrlTreeViewGetParentID($Treeview_Left, $curritem) WEnd $str_ldap = $str_ldap & "ou=" & _GUICtrlTreeViewGetText($Treeview_Left, $curritem) & "," & $strDNSDomain Return $str_ldap EndFunc Func DisableAllBtns() GUICtrlSetState($button, $GUI_DISABLE) GUICtrlSetState($Btn_GetProperties, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_LeftUserMemberOf, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_LeftGroupMembers, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_AddUsertoGroup, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_RemoveUserFromGroup, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_LeftDeleteGroup, $GUI_DISABLE) ;~ GUICtrlSetState($Btn_LeftCreateGroup, $GUI_DISABLE) EndFunc ;==>DisableAllBtns Func UpdateAllBtns() $leftclass = GetObjectTypeLeft() $leftfqdn = ReadFQDNFromGUILeft() If $leftfqdn <> "" Then $leftsam = _ADDNToSamAccountName ($leftfqdn) Else $leftsam = "" EndIf $remuser = 0 $adduser = 0 Select Case $leftclass = "user" And $rightclass = "group" If _ADIsMemberOf ($rightsam, $leftsam) = 1 Then $remuser = 1 Else $adduser = 1 EndIf Case $rightclass = "user" And $leftclass = "group" If _ADIsMemberOf ($leftsam, $rightsam) = 1 Then $remuser = 1 Else $adduser = 1 EndIf Case 1 EndSelect DisableAllBtns() ;~ Select ;~ Case $remuser ;~ GUICtrlSetState($Btn_RemoveUserFromGroup, $GUI_ENABLE) ;~ Case $adduser ;~ GUICtrlSetState($Btn_AddUsertoGroup, $GUI_ENABLE) ;~ EndSelect ;~ Select ;~ Case $leftclass = "user" ;~ GUICtrlSetState($Btn_LeftUserMemberOf, $GUI_ENABLE) ;~ Case $leftclass = "group" ;~ GUICtrlSetState($Btn_LeftGroupMembers, $GUI_ENABLE) ;~ GUICtrlSetState($Btn_LeftDeleteGroup, $GUI_ENABLE) ;~ Case $leftclass = "computer" ;~ EndSelect ;~ Select ;~ Case $rightclass = "user" ;~ GUICtrlSetState($Btn_RightUserMemberOf, $GUI_ENABLE) ;~ Case $rightclass = "group" ;~ GUICtrlSetState($Btn_RightGroupMembers, $GUI_ENABLE) ;~ GUICtrlSetState($Btn_RightDeleteGroup, $GUI_ENABLE) ;~ Case $rightclass = "computer" ;~ EndSelect EndFunc ;==>UpdateAllBtns Func GetSelectedNames() $ret = _GUICtrlListGetSelItemsText($List_left) If $ret <> "" Then For $i = 1 To $ret[0] MsgBox(0, "Selected", $ret[$i]) Next EndIf EndFunc Func GetProperties() $ret = _GUICtrlListGetSelItemsText($List_left) MsgBox(1,"$ret",$ret) If $ret <> "" Then For $i = 1 To $ret[0] _ADGetObjectAttribute($ret[0],"description") MsgBox(0, "Attribute = description", $return) Next EndIf EndFunc Func OnExit() Exit EndFunc ;==>OnExit ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
jefhal Posted April 26, 2007 Author Share Posted April 26, 2007 This was caused by GUICtrlRead($List_left) throwing out garbage! I put a msgbox in there to test what was in the "empty" list view box, and it wasn't empty!! It had a variety of odd characters, including a box, an I-umlaut, a degree sign, etc. So I replaced the empty test with a slightly different one: Func ReadFQDNFromGUILeft() If GUICtrlRead($Treeview_Left) = 0 Then Return "" If GUICtrlRead($List_left) = "" Or StringLen(GUICtrlRead($List_left)) < 5 Then GUICtrlSetData($List_left, "") Return "" EndIf oÝ÷ Øìµæ¡ö®¶s`¤gVæ2&VDeDäg&öÔuTÆVgB buT7G&Å&VBb33cµG&VWfWuôÆVgBÒFVâ&WGW&âgV÷C²gV÷C° buT7G&Å&VBb33c´Æ7EöÆVgBÒgV÷C²gV÷C²FVâ&WGW&âgV÷C²gV÷C° oÝ÷ ØÚ0¶ª¹ë-â±hrÈ.Ëk·vØk£§«m¨Â§¶¥Ë[£¬zjmÈw«yªÞ¶¥Ë[£Z©µêì=êáj-槳«È§¶«y«¢+ØÀÌØí1¥ÍÑ}±ÐôU% Ñɱ ÉÑ1¥ÍÐ ÅÕ½ÐìÅÕ½Ðì°ÈÄÀ°ÄÀ°ÈÀÀ°ØÜÔ° ¥Ñ=H ÀÌØí1 M}M=IP°ÀÌØí]M} =IH°ÀÌØí]M}YM I=10°ÀÌØí1 M}9=Q%d°ÀÌØí1 M}5U1Q%A1M0¤¤ ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
evilertoaster Posted April 26, 2007 Share Posted April 26, 2007 Maybe it doesn't like using a normal guictrlread on a multi-select list.... what if you use _GUICtrlListGetSelItemsText () from GuiList.au3? Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2007 Share Posted April 26, 2007 The script is too long to read the problem easily. A much shorter version demo that still displayed the symptoms would be nice. Just a hunch from reading your descriptions: Might you be getting values back and adding them to the list view or tree view that are not ANSI strings? Maybe Unicode text, or an object pointer, or...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jefhal Posted April 26, 2007 Author Share Posted April 26, 2007 Hi PsaltyDS- I realized that since I was using #include <GuiList.au3> to make my list that I could use _guictrllistcount to check if the list was empty. For some reason this works, even though the list itself returns "stuff" when queried by guictrlread. _guictrllistcount returns a 0 if the list box "looks" empty, which is good enough for now. However, you may be on the right track. I'm not sure how the Unicode or pointers could be getting into the list box, but they look like extended ansi or double-byte characters... This works for me:Func ReadFQDNFromGUILeft() If GUICtrlRead($Treeview_Left) = 0 Then Return "" If _GUICtrlListCount($List_left) = 0 Then Return "" The script is too long to read the problem easily. A much shorter version demo that still displayed the symptoms would be nice. Just a hunch from reading your descriptions: Might you be getting values back and adding them to the list view or tree view that are not ANSI strings? Maybe Unicode text, or an object pointer, or...? ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
evilertoaster Posted April 26, 2007 Share Posted April 26, 2007 can't use guictrlread for a multi-slect list (what could it return if there's more than 1 item slected?) use _GUICtrlListGetSelItemsText () Link to comment Share on other sites More sharing options...
jefhal Posted April 26, 2007 Author Share Posted April 26, 2007 evilertoaster- that's twice in one week that you've helped me out. Thank you! Now I'm fighting with what exactly _guictrllistgetselitemstext is returning. If I try to do an _arrayDisplay on the return value, I get nothing. However, if I use _arraytostring then I get stuff! I'm going home!can't use guictrlread for a multi-slect list (what could it return if there's more than 1 item slected?) use _GUICtrlListGetSelItemsText () ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
evilertoaster Posted April 26, 2007 Share Posted April 26, 2007 those _array functions are just automatic manpulations the array to certian things. I don't know why _arraydisplay wouldn't work but keep in mind if the data it is diplaying is not a string it might not display. looking at the help file for _guictrllistgetselitemstext it makes a simple array so you'd want somthin like $items=_guictrllistgetselitemstext($somelist)oÝ÷ ÛMúצ³G(Ö¢Ëaz{¦mêâ~+^ÊÞ¶êçyÜ!ÈZêh¦éZµçbØ^jºÚÊÊ-¯)æ¥'hxºÚ"µÍÜ ÌÍÚOLHÈ ÌÍÚ][ÖÌBÙØÞ ][ÝÉ][ÝË ÌÍÚ][ÖÉÌÍÚWJB^ and see what it spits at ya... Link to comment Share on other sites More sharing options...
jefhal Posted April 26, 2007 Author Share Posted April 26, 2007 This definitely works like you said: for $i=1 to $items[0] msgbox(0,"",$items[$i]) next Maybe the _arraydisplay fails because it is some kind of multiple-dimension array and I don't know it? Thanks again! ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format 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