Jump to content

playing with arrays and lists


31290
 Share

Recommended Posts

Hi everyone, 

I have an array which is populated among results found with the AD UDF. So there can be hundreds of results. This array is output in a txt file in order to read the lines:

Here's some lines:

307|3|
USERID|CN=XXXX,OU=Users,OU=SITE,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX|NAME, FIRST NAME
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Mexico,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Argentina,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX

The first value is the number of returned results; the second one is the number of rows of the array. The file will always be outputted like the "code" above.

What I would like to achieve is to put all results in a listbox looking like the "windows explorer". I mean that it would contain 5 row that can be sorted by the "headers" (I've uploaded a photo to better explain). Also, I'd like to have the possibility to double click on a line where the value in the "User ID" would be stored in a variable (for further treatment but I know what to do with it ^^)

I know this can be a "huge" request but I've no idea where to start or how to achieve it.

Thanks in advance to all that can offer help, I'm sure my knowledge will grow :) 

Bye

Untitled.png

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Thanks johnOne, 

That's a good start indeed. But what miss me is how to extract data from the array and place them accordingly to my needs. 

Also, is it mandatory for me to export the array content to a file and then read the file? Seems a bit to complicated for me :/

 

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Thanks again johnOne, 

 

That's also a very nice function that will be very handy. 

But I still don't know how to read from the array to extract only data I want to put in the list. 

Can you please help?

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

As a start i suggest the following:
Sorting isn't implemented yet.
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $sTemp = ""
Global $aResult[][] = [[3, 3], ["USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME1, FIRST NAME"], ["USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME2, FIRST NAME"], ["USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME3, FIRST NAME"]]
GUICreate("Active Directory Information", 420, 450)
Global $idListview = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
For $i = 1 To $aResult[0][0]
    $sTemp = $aResult[$i][2] & "|" & $aResult[$i][0] & "|" & $aResult[$i][1]
    GUICtrlCreateListViewItem($sTemp, $idListview)
Next
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Do you really read the data from a file? Or do you retrieve the data from AD in your script an populate an array?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi Water and thanks for your input. 

Indeed, I retrieve data right from your AD UDF by doing this: 

$aObjects = _AD_GetObjectsInOU("", "(ANR=" & $currentUser & ")", 2, "sAMAccountName,distinguishedName,displayname", "displayname")

And this array (I think this will be limited to the 500 first results if more) can have lots of results.

What annoys me the most in fact, is on how to get only the "SITE"  from "OU=SITE" and the "COUNTRY" defined by "OU=Country" (Brazil, Mexico, etc...) because it's in the same row that all the crap around.

I could have populated the array with other things with "LDAP Names" but I think OU's are the best because some other information can be forgotten by the user's creator.

Hope this is clear enough :)

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Something like this?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <AD.au3>

; _AD_Open()
; Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
; _AD_Close()
Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp = ""
GUICreate("Active Directory Information", 420, 450)
Global $idListview = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $idListview)
Next
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

New version with sort and alternate colors:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

; _AD_Open()
; Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
; _AD_Close()
Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water, 

WOW! That is huge! Thanks thanks thanks :)

This is exactly what I imagined!

I see you manually populated the array, is there a way to populate it right from the _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname") ?

:)

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Sure. Remove line

Global $aResult[][] = [[3, 3], [" ...

and the comments in the 3 lines above.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water, 

 

Thanks again but I do have an error while following your instructions.

Here's the code:

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Can you please help?

24-09-2015 17-22-57.jpg

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

_AD_Open is missing at the top of your script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Sorry, I forgot to paste it. I can assure you it's present. 

Here's the whole code:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")


_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Hope it helps you :)

Edited by 31290
formatting

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Let's display the array that causes the error:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")

_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
_ArrayDisplay($aTemp) ; <== This line is new
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

That looks good. I have to check the code tomorrow when I return to my office.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

One last idea for today. Lets check on which of the 507 records the get the error. Please run this version from SciTE so we can see the output.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")

_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
ConsoleWrite($i & @CRLF)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water, 

Here's the output:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\h74033\Downloads\GUICtrlCreateListView.au3"    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"C:\Users\h74033\Downloads\GUICtrlCreateListView.au3" (44) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & ^ ERROR
>Exit code: 1    Time: 2.001

If I comment 

& "|" & $aTemp[3] & "|" & $aTemp[4]

And let 

$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] ;& "|" & $aTemp[3] ;& "|" & $aTemp[4]

I got what I attached (sorry, had to hide the names). SITE and COUNTRY are missing though.

array.jpg

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
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
 Share

×
×
  • Create New...