Sign in to follow this  
Followers 0
colombeen

Capture more than 1 result

9 posts in this topic

#1 ·  Posted (edited)

Hi guys

I'm writing an AD viewer with the AD UDF from Water. what i'm doing now is, when I search for something, and when i get more then 1 result, I only show an _arrayDisplay () and when it's only 1 result, I fill the information in the form.

I'd like to know how to add something in my function to show a popup in which you can select only 1 result and that result should be processed by the "fill form" part.

Only problem is that I don't know how to get started.

This is everything (it might not be the best code but i'm trying)

The function that i'm talking about is Func _AD_Gather_Information () at the top of functions.au3

Anyone who can help me?

Screenshot : 

screenshotDigiAD.png

DigiAD.au3 : 

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Outfile=DigiAD.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Comment=This tool was made by Jarno Colombeen
#AutoIt3Wrapper_Res_Description=DigiAD is an alternative tool for the default Active Directory tool
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_ProductVersion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=Jarno Colombeen
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;========================================================================;
#cs

    Script:         DigiAD
    Author:         Jarno Colombeen
    Copyright:      colombeen.be

    Description:    DigiAD is an alternative tool for the default
                    Active Directory tool

    Date:           19/08/2014
    AutoIt Version: 3.3.10.2

#ce
Opt("GuiOnEventMode", 1)
;========================================================================;
; General variables
;========================================================================;
    Global $DigiAD, $DigiAD_PopUp
    Global $SearchInput, $SearchButton, $SearchButtonReset
    Global $TU_Picture, $TU_Name, $TU_TelephoneNr, $TU_Email, $TU_Description, $TU_Company, $TU_Department, $TU_Title, $TU_Office
    Global $TU_Username, $TU_A_Expires, $TU_P_Expires, $TU_P_Set, $TU_Custom10, $TU_Custom2, $TU_HomeDrive, $TU_Logonscript
    Global $TU_A_Locked, $TU_A_Disabled, $TU_A_Expired, $TU_P_Expired, $TU_P_Change
    Global $TU_MemberOf
    Global $colorRed    =   0xFF0000
    Global $colorGreen  =   0x00CC00
    Global $colorWhite  =   0xFFFFFF
    Global $colorBlack  =   0x00000
;========================================================================;
; Required files
;========================================================================;
    #include <AD.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <StringConstants.au3>
    #include <TabConstants.au3>
    #include <WindowsConstants.au3>
    #include "functions.au3"
;========================================================================;
; Init App
;========================================================================;
Func _init ()
    ; Open AD connection
    _AD_Open ()
    If @error Then Exit MsgBox(16, "DigiAD", "Er kan geen verbinding worden gemaakt met Active Directory." & @CRLF & "Error : " & @error & @CRLF & "Extended : " & @extended)

    ; GUI
    $DigiAD             =   GUICreate ("DigiAD", 900, 700)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetFont (_fontsizeDPI (8), 400, 0, "Verdana", $DigiAD)
    GUICtrlSetDefColor ($colorBlack, $DigiAD)

    ; GUI Menubar
    $menu_file          =   GUICtrlCreateMenu("Bestand")
    $menu_file_quit     =   GUICtrlCreateMenuItem("Sluiten", $menu_file)
    GUICtrlSetOnEvent (-1, "_Exit")
    $menu_help          =   GUICtrlCreateMenu("Help")
    $menu_help_about    =   GUICtrlCreateMenuItem("Over DigiAD", $menu_help)

    ; GUI Tabs
    $Tabs               =   GUICtrlCreateTab (5, 5, 890, 670, $TCS_FOCUSNEVER)
    $TabUser            =   GUICtrlCreateTabItem (" Account informatie ")

    ;==================== ACCOUNT INFO ====================
    ; Search
    GUICtrlCreateGroup (" Zoeken ", 20, 40, 860, 47)
    _GUICtrlCreateLabel ("Naam", 160, 58, 50, 20, 0)
    $SearchInput        =   GUICtrlCreateInput ("", 220, 56, 240, 20)

    $SearchButton       =   GUICtrlCreateButton ("Zoeken", 480, 54, 90, 24, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent (-1, "_AD_Gather_Information")
    $SearchButtonReset  =   GUICtrlCreateButton ("Alles wissen", 580, 54, 120, 24)
    GUICtrlSetOnEvent (-1, "_AD_Reset_Fields")
    ; General
    GUICtrlCreateGroup (" Algemeen ", 20, 103, 350, 200)
    $TU_Picture         =   GUICtrlCreatePic ("", 300, 125, 60, 90)
    _GUICtrlCreateLabel ("Naam", 35, 125, 50, 20, 0)
    $TU_Name            =   GUICtrlCreateInput ("", 100, 123, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Telefoon", 35, 146, 50, 20, 0)
    $TU_TelephoneNr     =   GUICtrlCreateInput ("", 100, 144, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("E-mail", 35, 167, 50, 20, 0)
    $TU_Email           =   GUICtrlCreateInput ("", 100, 165, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Bedrijf", 35, 188, 50, 20, 0)
    $TU_Description     =   GUICtrlCreateInput ("", 100, 186, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Groep", 35, 209, 50, 20, 0)
    $TU_Company         =   GUICtrlCreateInput ("", 100, 207, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Cel", 35, 230, 50, 20, 0)
    $TU_Department      =   GUICtrlCreateInput ("", 100, 228, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Functie", 35, 251, 50, 20, 0)
    $TU_Title           =   GUICtrlCreateInput ("", 100, 249, 190, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Kantoor", 35, 272, 50, 20, 0)
    $TU_Office          =   GUICtrlCreateInput ("", 100, 270, 190, 20, $ES_READONLY)
    ; Account
    GUICtrlCreateGroup (" Account ", 390, 103, 280, 200)
    _GUICtrlCreateLabel ("Gebruiker", 405, 125, 100, 20, 0)
    $TU_Username        =   GUICtrlCreateInput ("", 500, 123, 156, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Account verloopt", 405, 146, 116, 20, 0)
    $TU_A_Expires       =   GUICtrlCreateInput ("", 520, 144, 136, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Paswoord verloopt", 405, 167, 116, 20, 0)
    $TU_P_Expires       =   GUICtrlCreateInput ("", 520, 165, 136, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Paswoord ingesteld", 405, 188, 116, 20, 0)
    $TU_P_Set       =   GUICtrlCreateInput ("", 520, 186, 136, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("RRNR", 405, 209, 100, 20, 0)
    $TU_Custom10        =   GUICtrlCreateInput ("", 500, 207, 156, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("MFK-code", 405, 230, 100, 20, 0)
    $TU_Custom2         =   GUICtrlCreateInput ("", 500, 228, 156, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Homedrive (H:)", 405, 251, 100, 20, 0)
    $TU_HomeDrive       =   GUICtrlCreateInput ("", 500, 249, 156, 20, $ES_READONLY)
    _GUICtrlCreateLabel ("Logonscript", 405, 272, 100, 20, 0)
    $TU_Logonscript     =   GUICtrlCreateInput ("", 500, 270, 156, 20, $ES_READONLY)
    ; Status
    GUICtrlCreateGroup (" Status ", 690, 103, 190, 200)
    $TU_A_Locked        =   GUICtrlCreateCheckbox (" Account geblokkeerd", 705, 125, 160, 20)
    GUICtrlSetState (-1, $GUI_DISABLE)
    $TU_A_Disabled      =   GUICtrlCreateCheckbox (" Account uitgeschakeld", 705, 146, 160, 20)
    GUICtrlSetState (-1, $GUI_DISABLE)
    $TU_A_Expired       =   GUICtrlCreateCheckbox (" Account verlopen", 705, 167, 160, 20)
    GUICtrlSetState (-1, $GUI_DISABLE)
    $TU_P_Expired       =   GUICtrlCreateCheckbox (" Paswoord verlopen", 705, 188, 160, 20)
    GUICtrlSetState (-1, $GUI_DISABLE)
    $TU_P_Change        =   GUICtrlCreateCheckbox (" Paswoord wijzigen vereist", 705, 207, 160, 20)
    GUICtrlSetState (-1, $GUI_DISABLE)
    ; MemberOfGroups
    GUICtrlCreateGroup (" Rechtengroepen ", 20, 310, 350, 350)
    $TU_MemberOf        =   GUICtrlCreateList ("", 35, 330, 320, 320, BitOR ($LBS_SORT,$LBS_STANDARD,$WS_VSCROLL))

    ;==================== ACCOUNT INFO ====================

    $TabComp            =   GUICtrlCreateTabItem (" Accounts vergelijken ")

    ;=================== ACCOUNT COMPARE ==================

    ;=================== ACCOUNT COMPARE ==================

    $TabSys             =   GUICtrlCreateTabItem (" Toestel informatie ")

    ;===================== SYSTEM INFO ====================

    ;===================== SYSTEM INFO ====================

    $TabEnd             =   GUICtrlCreateTabItem ("")

    GUISetState ()

    ControlFocus ($DigiAD, "", "Edit1")

    While 1
        Sleep (100)
    WEnd
EndFunc
;========================================================================;
; End App
;========================================================================;
_init ()

functions.au3 : 

#include <Crypt.au3>
#include <StaticConstants.au3>
#include <String.au3>
Func _AD_Gather_Information ()
    If GUICtrlRead ($SearchInput) <> "" Then
        $AD_query   =   _AD_GetObjectsInOU("", "(ANR=" & GUICtrlRead ($SearchInput) & ")", 2, _
        "extensionattribute6,displayname,telephoneNumber,mail,description,company,department,title,physicalDeliveryOfficeName," & _
        "sAMAccountName,extensionattribute10,extensionattribute2,homeDirectory,ScriptPath," & _
        "pwdLastSet", "displayname")
        If @error > 0 Then Return False
        If UBound ($AD_query) = 2 Then
            $PassInfo   =   _AD_GetPasswordInfo ($AD_query[1][9])
            If Not $AD_query[1][0] = "" Then
                GUICtrlSetImage ($TU_Picture, $AD_query[1][0], 0, 0)
            Else
                GUICtrlSetImage ($TU_Picture, "", 0, 0)
            EndIf
            GUICtrlSetData ($TU_Name, $AD_query[1][1])
            GUICtrlSetData ($TU_TelephoneNr, $AD_query[1][2])
            GUICtrlSetData ($TU_Email, $AD_query[1][3])
            GUICtrlSetData ($TU_Description, $AD_query[1][4])
            GUICtrlSetData ($TU_Company, $AD_query[1][5])
            GUICtrlSetData ($TU_Department, $AD_query[1][6])
            GUICtrlSetData ($TU_Title, $AD_query[1][7])
            GUICtrlSetData ($TU_Office, $AD_query[1][8])

            GUICtrlSetData ($TU_Username, $AD_query[1][9])
            If _AD_GetAccountExpires ($AD_query[1][9]) <> 0 Then
                GUICtrlSetData ($TU_A_Expires, StringRegExpReplace (_AD_GetAccountExpires ($AD_query[1][9]), "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "$1/$2/$3 $4:$5:$6"))
            Else
                GUICtrlSetData ($TU_A_Expires, "Nooit")
            EndIf
            If $PassInfo[9] = "" Then $PassInfo[9] = "Nooit"
            GUICtrlSetData ($TU_P_Expires, $PassInfo[9])
            GUICtrlSetData ($TU_P_Set, $Passinfo[9])
            GUICtrlSetData ($TU_Custom10, $AD_query[1][10])
            GUICtrlSetData ($TU_Custom2, $AD_query[1][11])
            GUICtrlSetData ($TU_HomeDrive, $AD_query[1][12])
            GUICtrlSetData ($TU_Logonscript, $AD_query[1][13])

            If _AD_IsObjectLocked ($AD_query[1][9]) = 1 Then
                GUICtrlSetState ($TU_A_Locked, $GUI_ENABLE + $GUI_CHECKED)
            Else
                GUICtrlSetState ($TU_A_Locked, $GUI_DISABLE + $GUI_UNCHECKED)
            EndIf
            If _AD_IsObjectDisabled ($AD_query[1][9]) = 1 Then
                GUICtrlSetState ($TU_A_Disabled, $GUI_ENABLE + $GUI_CHECKED)
            Else
                GUICtrlSetState ($TU_A_Disabled, $GUI_ENABLE + $GUI_UNCHECKED)
            EndIf
            If _AD_IsAccountExpired ($AD_query[1][9]) = 1 Then
                GUICtrlSetState ($TU_A_Expired, $GUI_ENABLE + $GUI_CHECKED)
            Else
                GUICtrlSetState ($TU_A_Expired, $GUI_DISABLE + $GUI_UNCHECKED)
            EndIf
            If _AD_IsPasswordExpired ($AD_query[1][9]) = 1 And GUICtrlRead ($TU_P_Expires) <> "Nooit" Then
                GUICtrlSetState ($TU_P_Expired, $GUI_ENABLE + $GUI_CHECKED)
            Else
                GUICtrlSetState ($TU_P_Expired, $GUI_DISABLE + $GUI_UNCHECKED)
            EndIf
            If $AD_query[1][14] = 0 Then
                GUICtrlSetState ($TU_P_Change, $GUI_ENABLE + $GUI_CHECKED)
            Else
                GUICtrlSetState ($TU_P_Change, $GUI_ENABLE + $GUI_UNCHECKED)
            EndIf
            $UserGroups     =   _AD_GetUserGroups ($AD_query[1][9])
            GUICtrlSetData ($TU_MemberOf, "")
            For $i = 1 To $UserGroups[0]
                $stripped   =   StringMid (StringSplit ($UserGroups[$i], ",OU=", $STR_ENTIRESPLIT)[1], 4)
                GUICtrlSetData ($TU_MemberOf, $stripped)
            Next
        Else
            _ArrayDisplay($AD_query, "Search test")
        EndIf
    EndIf
EndFunc
Func _AD_Reset_Fields ()

EndFunc
;========================================================================;
; Function: Exit
;========================================================================;
Func _Exit ()
    _AD_Close ()
    Exit
EndFunc ; _Exit
;========================================================================;
; Function: Extended function to create the label
;========================================================================;
Func _GUICtrlCreateLabel($varText, $varLeft, $varTop, $varWidth, $varHeight, $varBold = 1, $varSize = 8, $varAlign = 0, $varColor = 0x000000, $varBkColor = $GUI_BKCOLOR_TRANSPARENT)
    $tempLabelId = GUICtrlCreateLabel($varText, $varLeft, $varTop, $varWidth, $varHeight) ; Create the label
    GUICtrlSetColor(Default, $varColor) ; Set the color
    GUICtrlSetBkColor(Default, $varBkColor)
    ; Set font weight
    If $varBold = 1 Then GUICtrlSetFont(Default, _fontsizeDPI ($varSize), 600)
    If $varBold = 0 Then GUICtrlSetFont(Default, _fontsizeDPI ($varSize), 400)
    ; Set text alignment
    If $varAlign = 1 Then
        GUICtrlSetStyle(Default, $SS_CENTER)
    ElseIf $varAlign = 2 Then
        GUICtrlSetStyle(Default, $SS_RIGHT)
    EndIf
    Return $tempLabelId
EndFunc ; _GUICtrlCreateLabel
;========================================================================;
; Function: Read the DPI and return the value
;========================================================================;
Func _fontsizeDPI ($fontSize)
    $DPI            =   RegRead ("HKCU\Control Panel\Desktop\WindowMetrics", "AppliedDPI")
    If @error <> 0 Then Return $fontSize
    If $DPI < 100 Then Return $fontSize
    If $DPI > 99 And $DPI < 130 Then Return Round (($fontSize / 5) * 4)
    If $DPI > 129 Then Return Round (($fontSize / 3) * 2)
EndFunc ; _fontsizeDPI
;========================================================================;
; Function: Encrypt or decrypt a string
;========================================================================;
Func StringCrypt ($method, $data)
    Local $return       =   ""
    Local $password     =   @ComputerName & @OSArch & @UserName

    _Crypt_Startup ()

    If $method Then
        ;   if true encrypt
        $return         =   _Crypt_EncryptData ($data, $password, $CALG_RC4)
    Else
        ;   if false decrypt
        $return         =   BinaryToString (_Crypt_DecryptData ($data, $password, $CALG_RC4))
    EndIf

    _Crypt_Shutdown ()
    Return $return
EndFunc ; StringCrypt
Edited by colombeen

Share this post


Link to post
Share on other sites



I have the feeling that nobody knows how to do this? isn't this possible? adding an extra GUI or something that displays the results and gives the option to select 1?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Given the code that you wrote above, it should be easy for you to create another gui with a listbox or listview control and return the selected item.

edit: wording

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

what about a listbox in your form?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

does a listbox support multiple columns? can't seem to find info on multiple columns.

Edited by colombeen

Share this post


Link to post
Share on other sites

if you need multiple columns use a listview control


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

multiple columns to select what?

 

in which you can select only 1 result and that result should be processed by the "fill form" part.

1 result....

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I want to show (multiple columns) username, name and e-mail (with multiple rows for all the results) from which you can select 1 and that 1 should be used to fill the form

at this point i'm thinking :

- check for more then 1 result

- if more put the results in a global var that can be used by both functions

- create a new gui with a listview???

- select 1 and press ok

- should return only the username to make sure its unique???

- continue the first function with the result that got returned but with a different query that checks specifically on the username without any other chars that could be added (so that it doesn't think again that there could be more results (like if you'd use abc but you also have an account abcd that it wouldn't think that there are 2 results)

what do you guys think?

Edited by colombeen

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