Sign in to follow this  
Followers 0
darkleton

Reading multi values from an array

6 posts in this topic

#1 ·  Posted (edited)

At the moment, I have a gui which gets all OUs from active dir, puts them in an array and builds them into a collapsible tree. what i then wanted was for a user to click on an ou and it will perform _AD_GetAllObjectsInOU. Unfortunately that command needs the full OU passing to it, and the array formatting shown puts just the OU name.

For example, the line below from the array is shown as "Associates" in the treeview, so if i tell something to read the $treeview it comes back with that, yet I need it to come back with the bit on the right (the OU=Associates full path).

This is still in the array but i dont know how to call it. I also have to watch as there are two OUs called DHS so just trying to search the array for DHS could cause errors.

Is there a way that by clicking on a line in the treeview i can get the line in the array from it and then reference the bit after the second pipe?

[8]|Establishments\DHS\Associates|OU=Associates,OU=DHS,OU=Establishments,DC=derbyhigh,DC=internal

So what i was thinking is....is there a way if I click on "associates" in the treeview, it sees that it was number [8] in the array and can then format and return the part after the second pipe?

Edited by darkleton

Share this post


Link to post
Share on other sites



any ideas anyone? :(

Share this post


Link to post
Share on other sites

vaz ga baah duuh sh farquiled ven geer da gheen so vingi

understood me? well, this is what I understood from your explanation. Maybe you should try to explain it, so not only you can understand.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

vaz ga baah duuh sh farquiled ven geer da gheen so vingi

understood me? well, this is what I understood from your explanation. Maybe you should try to explain it, so not only you can understand.

a simple "i dont understand what you mean please could you explain it a bit better" would have sufficed, not a sarcastic reply!

Using _AD_GetAllOUs it will create an array like

[0]|Establishment|OU=Establishment,DC=mydomain,DC=com

[1]|Establishment\Room1|OU=Room1,OU=Establishment,DC=mydomain,DC=com

The middle part (Establishment\Room for example) is then cleaned up in a treeview so that Establishment is the parent and Room1 is the child.

What I then want is for a user to click on a button which will call _AD_GetObjectsInOU on the selected OU in the treeview (for example Room1).

My problem is that I can't tell it to just read the treeview as it needs a FQDN (which is col 1 in the array).

So I need a way of finding out what row number they have clicked on (for example [1] for Room1) and then outputting the col 1 (OU=Room1,OU=xxxx) so it can be used with the getobjects function.

If needed I can attach the script, but it's not very tidy at the moment

Share this post


Link to post
Share on other sites

I still dont quite understand why would someone put a tree into a column & then put another tree into another column... it just makes no sense. post your gui sample please.

PS: you have checkked out the GUICtrlTreeView management functions in the help file right? There are over 100 functions for you to use to work with the tree.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi,

based on the treeview code posted on former thread.

See remarks for changes and new function at end:

#Include <GUIConstants.au3>
#Include <GuiListView.au3>
#include <WindowsConstants.au3>
;#include <adfunctions_.au3>
#include <ad.au3>
#include <Constants.au3>
#Include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>

Const $ouIdentifier     = "OU="
Const $cnIdentifier     = "CN="
Const $ouSeparator      = "\"


Global $gui = GUICreate("Test",800,600)
_filllistv ()
GUISetState()
;change
$checktree = GUICtrlRead ($defaultTreeView)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    ;change
    If IsNumber (Number (GUICtrlRead ($defaultTreeView))) And  GUICtrlRead ($defaultTreeView) <> $checktree Then 
        $checktree = GUICtrlRead ($defaultTreeView)
        MsgBox (0,"",getou ()) ; Add function you want
    EndIf   
WEnd

Func _filllistv ()
    Dim $allOUsArray
    _ad_open ()
    $arAllOU = _Ad_GetAllOUs ()
    _ad_close ()
    _ArrayDelete ($arAllOU, 0)
    Global $defaultTreeView = GUICtrlCreateTreeView (5, 5, 399, 590, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER), $WS_EX_CLIENTEDGE)
    ;GUICtrlSetOnEvent(-1, "GetOU")

    ;------------------------------------------------------------------------------
    ; Reverse the order of all the OUs so we can do an easy alpabetical sort
    ; on the names
    ;------------------------------------------------------------------------------                     
    Dim $reversedAllOUsArray[1]
    For $i = 0 To UBound ($arAllOU, 1) - 1
        $reversedOU     = returnReversedOU($arAllOU [$i] [0])
        $arrayAddStatus = _ArrayAdd($reversedAllOUsArray, $reversedOU)  
    Next

    ;------------------------------------------------------------------------------
    ; Sort the array alpabetically
    ;------------------------------------------------------------------------------
    $sortRevArrayStatus = _ArraySort($reversedAllOUsArray)      

    ;------------------------------------------------------------------------------
    ; Initialize our treeIDArray
    ; This will be used to look up the ID number of the GUI TreeView entries
    ; We need this to make nesting/child-parent relationships work.
    ;------------------------------------------------------------------------------
    Dim $treeIDArray[UBound($reversedAllOUsArray)*2]

    ;------------------------------------------------------------------------------
    ; Return the OUs to their original format and create the TreeView Entries.
    ;------------------------------------------------------------------------------
    $adCurrentObjectNumber = 0
    For $i = 0 To UBound ($arAllOU) - 1
        ;------------------------------------------------------------------------------
        ; Reverse the order back to the orginal format  
        ;------------------------------------------------------------------------------ 
        $ou = returnReversedOU($arAllOU [$i] [0])
        ;If StringInStr ($ou, "PGO") = 0 And StringInStr ($ou, "IE Zugriff") = 0 Then ContinueLoop
        ;------------------------------------------------------------------------------
        ; Calculate the additional values for this OU and check to see if its
        ; parentou has a GUI TreeID
        ;------------------------------------------------------------------------------     
        $fullOU         = StringStripWS($ou, 3)
        $friendlyOU     = returnFriendlyName($fullOU)           
        $parentFullOU   = returnParentOU($fullOU)           
        $parentTreeID   = _ArraySearch($treeIDArray, $parentFullOU)
        ;------------------------------------------------------------------------------
        ; Check if this OU has a parent. If it does make this TreeView item a child
        ; of that parent.
        ;------------------------------------------------------------------------------
        If ( $parentTreeID <> "-1" ) Then   
            $treeID = GUICtrlCreateTreeViewItem ($friendlyOU, $parentTreeID)
        Else   
            $treeID = GUICtrlCreateTreeViewItem ($friendlyOU, $defaultTreeView)
        EndIf   
        ;------------------------------------------------------------------------------
        ; The returned $treeID is sequential. We can use this to cheat and emulate
        ; a hashtable.
        ;------------------------------------------------------------------------------
        $treeIDArray[$treeID] = $fullOU
        $adCurrentObjectNumber = $adCurrentObjectNumber + 1
    Next
EndFunc

Func returnReversedOU($ou)
    $subOUArray = StringSplit($ou, $ouSeparator)
    $reversedOU = ""
    For $i = (UBound($subOUArray) - 1 ) To 1 Step -1 
        If $i = (UBound($subOUArray) -  1 ) Then
            $reversedOU = $reversedOU & $subOUArray[$i]
        Else
            $reversedOU = $reversedOU & $ouSeparator & $subOUArray[$i]
        EndIf
    Next
    return $reversedOU
EndFunc

;------------------------------------------------------------------------------
; Returns the friendly object name:
;
; Example:
;
; The full OU of:
; OU=IT Shop,OU=Service Groups,DC=domain,DC=com
;
; Is returned as:
; IT Shop
;------------------------------------------------------------------------------ 
Func returnFriendlyName($dn)
    return StringMid($dn, StringInStr($dn, "=")+1, StringInStr($dn, $ouSeparator)-(StringInStr($dn, "=")+1))
EndFunc

;------------------------------------------------------------------------------
; Returns the full OU name from a DN record:
;
; Example:
;
; The DN:
; CN=Paula,OU=IT Shop,OU=Service Groups,DC=domain,DC=com
;
; Is returned as:
; OU=IT Shop,OU=Service Groups,DC=domain,DC=com
;------------------------------------------------------------------------------ 
Func returnFullOUfromDN($dn)
    If $dn <> "0" Then
        return StringRight($dn, StringLen($dn)-StringInStr($dn, $ouIdentifier)+1)
    Else
        return 0
    EndIf
EndFunc

;------------------------------------------------------------------------------
; Returns the parent OU name:
;
; Example:
;
; The full OU of:
; OU=IT Shop,OU=Service Groups,DC=domain,DC=com
;
; Is returned as:
; OU=Service Groups,DC=domain,DC=com
;------------------------------------------------------------------------------ 
Func returnParentOU($fullOU)
    return StringRight($fullOU, ( StringLen($fullOU)-StringInStr($fullOU, $ouSeparator) ) )
EndFunc

;new function
Func getou ()
    $ousearch = ""
    $ou =  _GUICtrlTreeView_GetText ($defaultTreeView, GUICtrlRead ($defaultTreeView))
    $select = GUICtrlRead ($defaultTreeView)
    While 1
        If _GUICtrlTreeView_GetParentHandle($defaultTreeView, $select) Then
            $ou = _GUICtrlTreeView_GetText ($defaultTreeView, _GUICtrlTreeView_GetParentHandle($defaultTreeView, $select)) & "/" & $ou
            $select = _GUICtrlTreeView_GetParentHandle($defaultTreeView, $select)
        Else
            ExitLoop
        EndIf
    WEnd
    $temp = StringSplit ($ou, "/")
    For $i = UBound ($temp) - 1 To 1 Step -1
        $ousearch = $ousearch & "ou=" & $temp [$i] & ","
    Next
    Return $ousearch & "dc=my, dc=domain, dc=Local" ; change to your domain
    EndFunc

@Edit: While i was driving home: you may not need:

If IsNumber (Number (GUICtrlRead ($defaultTreeView))) And GUICtrlRead ($defaultTreeView) <> $checktree

Maybe this works as well, but can't test at home:

If GUICtrlRead ($defaultTreeView) <> $checktree

Edited by 99ojo

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0