Jump to content

gui problems ldap


Recommended Posts

i got a problem with compiling my gui, i got these errors

>Running AU3Check (1.54.9.0) from:C:\Programme\AutoIt3

C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3(19,59) : WARNING: $Button_1 possibly not declared/created yet

$Button_1 = GUICtrlCreateButton ("LDAP Req", 10, 30, 100)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3(20,57) : WARNING: $Button_2 possibly not declared/created yet

$Button_2 = GUICtrlCreateButton ( "Button Test", 0, -1)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3(26,23) : WARNING: $msg possibly not declared/created yet

$msg = GUIGetMsg()

~~~~~~~~~~~~~~~~~~~~~~^

C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3 - 0 error(s), 3 warning(s)

->12:42:04 AU3Check ended.rc:1

>Running:(3.2.8.1):C:\Programme\AutoIt3\autoit3.exe "C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3"

C:\Dokumente und Einstellungen\hertzerr\Desktop\mac addres.au3 (19) : ==> Variable used without being declared.:

$Button_1 = GUICtrlCreateButton ("LDAP Req", 10, 30, 100)

^ ERROR

#NoTrayIcon
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Inet.au3>
#include <Constants.au3>

Global Const $Cursor_ARROW = 2
Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20

opt('MustDeclareVars', 1)
opt("GUIResizeMode", 1)



GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("LDAP Req",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "Button Test",  0, -1)

GUISetState ()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            _Main()
        Case $msg = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
    EndSelect
Wend





Func _Main()

    Local $s_Machine, $t_input = "", $num_pcs = 0, $item_num = 0
    Local $Title = "Computer list", $MAIN_WINDOW
    Local $Domain, $filter, $filters, $win_state, $Retrieve_Method
    Local $exititem
    Local $Domainitem, $Filtermenu, $Filteritem, $PingTimeOutitem, $FilterIPitem
    Local $ib_search, $Btn_Search, $Btn_Exit, $i_TimeOut
    Local $lv_pcs, $lv_pcs_contextmenu, $lv_pcs_contextRefresh, $lv_pcs_contextPopulate
    Local $lv_pcs_pslist_taskmodetree, $lv_pcs_pslist_taskmode, $lv_pcs_pslist
    Local $tabs, $tab_pids, $tab_hotfixes
    Local $lv_allsoftware, $lv_allsoftware_contextmenu, $lv_allsoftware_contextRefresh
    Local $lv_pid, $lv_pid_contextmenu, $lv_pid_contextKill, $lv_pid_contextRefresh
    Local $Status, $dll, $msg, $MOUSE_POS, $explore_with, $eb_system
    Local $tab_loggedin, $lv_loggedin, $tab_drives, $lv_drives, $lv_drives_contextmenu, $lv_drives_contextExplore
    Local $tab_services, $lv_services, $lv_services_contextmenu, $lv_service_stop, $lv_service_contextRefresh, $lv_service_start
    Local $lv_service_pause, $lv_service_resume, $lv_service_delete
    Local $lv_service_startmode, $lv_service_startmodeBoot, $lv_service_startmodeSystem, $lv_service_startmodeAutomatic
    Local $lv_service_startmodeManual, $lv_service_startmodeDisabled
    Local $configmenuRetrieveMethods, $ldapitem, $netvitem, $IP_Range = "", $Use_IPRange
    #endregion **** end variable declares *****
    
    TCPStartup()

    $Domain = "nea-group.intern"
    $filter = "*"
    $Retrieve_Method = "LDAP"
    $explore_with = "iexplore"
    $i_TimeOut = 4
    $filters = StringSplit($filter, "|")
    
    $MAIN_WINDOW = GUICreate($Title, 280, 560, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))

    $lv_pcs = GUICtrlCreateListView("Machine|IP Address|ID", 0, 0, 276, 460, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_pcs, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    _GUICtrlListViewSetColumnWidth ($lv_pcs, 0, 100)
    _GUICtrlListViewSetColumnWidth ($lv_pcs, 1, 120)
    _GUICtrlListViewHideColumn ($lv_pcs, 2)
    $lv_pcs_contextmenu = GUICtrlCreateContextMenu($lv_pcs)


    GUISetState()
    

    
    If Not StringInStr($Domain, "YOUR-DOMAIN") Then
        If $Retrieve_Method = "LDAP" Then
            _RetrieveComputersLdap($lv_pcs, $Domain, $filters, $Status, $i_TimeOut, _
                     $lv_allsoftware, $lv_pid, $lv_drives, $lv_loggedin, $eb_system, $IP_Range)
        Else
            EndIf
    EndIf
    
    GUICtrlSetState($ib_search, $GUI_FOCUS)
    
    $dll = DllOpen("user32.dll")
    
    While 1
        $msg = GUIGetMsg()
        
        $win_state = WinGetState($MAIN_WINDOW)
        
        
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem
                ExitLoop
                             
            Case $msg = $Filteritem
                _ConfigFilters($filter, $MAIN_WINDOW)
                
            Case $msg = $FilterIPitem
                _ConfigIpRange($IP_Range, $Use_IPRange, $MAIN_WINDOW)
                
            Case $msg = $ldapitem
                If BitAND(GUICtrlRead($ldapitem), $GUI_CHECKED) Then
                    $Retrieve_Method = "LDAP"
                    GUICtrlSetState($netvitem, $GUI_UNCHECKED)
                EndIf
                
                
            Case $msg = $PingTimeOutitem
                _ConfigPingTimeOut($i_TimeOut, $MAIN_WINDOW)
                

        EndSelect
    WEnd
    DllClose($dll)

EndFunc   ;==>_Main

Func _RetrieveComputersLdap(ByRef $h_listview, ByRef $Domain, ByRef $filters, ByRef $pc_status, ByRef $ping_timeout, _
ByRef $lv_allsoftware, ByRef $lv_pid, ByRef $lv_drives, ByRef $lv_loggedin, ByRef $eb_system, $IP_Range = "")
    Local $lv_item, $num_pcs = 1, $inFilter
    _LockAndWait()
    GUICtrlSetData($eb_system, "")
    _GUICtrlListViewDeleteAllItems ($lv_allsoftware)
    _GUICtrlListViewDeleteAllItems ($lv_pid)
    _GUICtrlListViewDeleteAllItems ($lv_drives)
    _GUICtrlListViewDeleteAllItems ($lv_loggedin)
    _GUICtrlListViewDeleteAllItems ($h_listview)
    _GUICtrlListViewDeleteAllItems ($h_listview)
    _ResetLockWait()
    _GUICtrlListViewSetColumnWidth ($h_listview, 1, 140)
    _GUICtrlListViewHideColumn ($h_listview, 2)
    
    Local $ObjDomain = ObjGet("WinNT://" & $Domain)
    Local $ip_address, $pc_name
    For $Object In $ObjDomain
        $ip_address = ""
        If $Object.class = "Computer" Then
            $pc_name = $Object.Name
            $inFilter = 0
            If $filters[0] = 1 And $filters[1] = "*" Then
                $inFilter = 1
            Else
                For $x = 1 To $filters[0]
                    If StringUpper(StringMid($pc_name, 1, StringLen($filters[$x]))) = StringUpper($filters[$x]) Then
                        $inFilter = 1
                        ExitLoop
                    EndIf
                Next
            EndIf
            
            If $inFilter Then
                If IsArray($IP_Range) Then
                    For $x = 1 To $IP_Range[0]
                        Local $strIP = StringSplit(TCPNameToIP($pc_name), ".")
                        Local $low_r = StringSplit($IP_Range[$x], "-")
                        Local $high_r = $low_r[2]
                        $low_r = StringSplit($low_r[1], ".")
                        If (Int($strIP[1]) = Int($low_r[1]) And Int($strIP[2]) = Int($low_r[2]) And Int($strIP[3]) = Int($low_r[3])) And _
                                (Int($strIP[4]) >= Int($low_r[4]) And Int($strIP[4]) <= Int($high_r)) Then
                            $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview)
                            GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item)
                            _SetStatus($h_listview, _GUICtrlListViewGetItemCount ($h_listview) - 1, $pc_status, $ping_timeout)
                            _ReduceMemory()
                            GUICtrlSetData($pc_status, "Machines: " & $num_pcs)
                            $num_pcs += 1
                            ExitLoop
                        EndIf
                    Next
                Else
                    $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview)
                    GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item)
                    _SetStatus($h_listview, _GUICtrlListViewGetItemCount ($h_listview) - 1, $pc_status, $ping_timeout)
                    _ReduceMemory()
                    GUICtrlSetData($pc_status, "Machines: " & $num_pcs)
                    $num_pcs += 1
                EndIf
            EndIf
        EndIf
    Next
    _GUICtrlListViewSetColumnWidth ($h_listview, 0, 140)
    _GUICtrlListViewSetColumnWidth ($h_listview, 1, 100)
    _GUICtrlListViewHideColumn ($h_listview, 2)
    GUISetCursor($Cursor_ARROW, 1)
EndFunc   ;==>_RetrieveComputersLdap

Func _SetStatus(ByRef $lv_listview, $index, ByRef $Status, ByRef $ping_length)
    Local $pc_name = _GUICtrlListViewGetItemText ($lv_listview, $index, 0)
    Local $ip_address = '', $ping_time
    If $ping_length Then
        $ping_time = Ping($pc_name, $ping_length)
        If $ping_time Then
            Local $lv_item = _GUICtrlListViewGetItemText ($lv_listview, $index, 2)
            $ip_address = TCPNameToIP($pc_name)
            GUICtrlSetData($lv_item, $pc_name & "|" & $ip_address & "|" & $lv_item)
            _ReduceMemory()
            Return 1
        Else
            Local $lv_item = _GUICtrlListViewGetItemText ($lv_listview, $index, 2)
            If Ping($lv_item,250) Then
                
                GUICtrlSetData($lv_item, $pc_name & "|" &TCPNameToIP($pc_name)& "|" & $lv_item)
            Else
                GUICtrlSetData($lv_item, $pc_name & "|" &"---OFFLINE---"& "|" & $lv_item)
            EndIf
        EndIf
  
    EndIf
    _ReduceMemory()
    Return 0
EndFunc   ;==>_SetStatus

Func _GetRole(ByRef $s_pc, ByRef $Status)
    Local $objWMIService, $colComputer, $objComputer
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $s_pc & "\root\cimv2")
    If @error Then
        GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        Return
    EndIf
    $colComputer = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        Return
    EndIf
    For $objComputer In $colComputer
        If Int($objComputer.DomainRole) = 1 Then
            GUICtrlSetData($Status, $s_pc & " is WorkStation")
        ElseIf Int($objComputer.DomainRole) = 3 Then
            GUICtrlSetData($Status, $s_pc & " is Server")
        ElseIf Int($objComputer.DomainRole) = 4 Then
            GUICtrlSetData($Status, $s_pc & " is Backup Domain Controller")
        ElseIf Int($objComputer.DomainRole) = 5 Then
            GUICtrlSetData($Status, $s_pc & " is Primary Domain Controller")
        Else
            GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        EndIf
        Return $objComputer.DomainRole
    Next
EndFunc   ;==>_GetRole

Func _ConfigPingTimeOut(ByRef $i_TimeOut, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $TimeOut_msg, $TimeOut_Window
    $TimeOut_Window = GUICreate("Ping Time Out Config", 340, 140, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel("Ping Time Out (Milliseconds, 0 = no ping)", 10, 10, 320, 20, $ES_CENTER)
    Local $TimeOut_input = GUICtrlCreateInput($i_TimeOut, 90, 40, 150, 20, $ES_NUMBER)
    $Save = GUICtrlCreateButton("Save", 40, 100, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 180, 100, 120, 25)
    GUISetState()
    Do
        $TimeOut_msg = GUIGetMsg()
        Select
            Case $TimeOut_msg = $Save
                $i_TimeOut = Int(GUICtrlRead($TimeOut_input))
                IniWrite(@ScriptDir & '\AdminTool.ini', "Ping", "TimeOut", $i_TimeOut)
            Case $TimeOut_msg = $CLOSE
                ExitLoop
        EndSelect
    Until $TimeOut_msg = $GUI_EVENT_CLOSE
    GUIDelete($TimeOut_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigPingTimeOut

Func _ConfigFilters(ByRef $s_filter, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state
    Local $lv_filters, $a_filter, $x, $filter_input, $Add, $Delete
    $Filter_Window = GUICreate("Filter Config", 300, 220, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel('PC Name Filter', 20, 10, 250, 20)
    GUICtrlCreateLabel("All Example: *", 20, 25, 250, 20)
    GUICtrlCreateLabel("Example: Z", 20, 40, 250, 20)
    $lv_filters = GUICtrlCreateListView("Filters", 20, 70, 100, 100, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    _GUICtrlListViewSetColumnWidth ($lv_filters, 0, 90)
    $a_filter = StringSplit($s_filter, "|")
    For $x = 1 To $a_filter[0]
        GUICtrlCreateListViewItem($a_filter[$x], $lv_filters)
    Next
    $filter_input = GUICtrlCreateInput("", 140, 70, 120, 20)
    $Add = GUICtrlCreateButton("Add", 140, 100, 120, 25)
    $Delete = GUICtrlCreateButton("Delete", 140, 130, 120, 25)
    GUICtrlSetState($Delete, $GUI_DISABLE)
    $Save = GUICtrlCreateButton("Save", 20, 190, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 160, 190, 120, 25)
    GUISetState()
    Do
        $filter_msg = GUIGetMsg()
        Select
            Case $filter_msg = $Save
                If _GUICtrlListViewGetItemCount ($lv_filters) > 0 Then
                    $s_filter = ""
                    For $x = 0 To _GUICtrlListViewGetItemCount ($lv_filters) - 1
                        $s_filter = $s_filter & "|" & _GUICtrlListViewGetItemText ($lv_filters, $x, 0)
                    Next
                    $s_filter = StringTrimLeft($s_filter, 1)
                    IniWrite(@ScriptDir & '\AdminTool.ini', "Workstations", "filter", $s_filter)
                EndIf
            Case $filter_msg = $Delete
                _GUICtrlListViewDeleteItemsSelected ($lv_filters)
                GUICtrlSetState($Delete, $GUI_DISABLE)
            Case $filter_msg = $Add
                If StringLen(GUICtrlRead($filter_input)) Then GUICtrlCreateListViewItem(GUICtrlRead($filter_input), $lv_filters)
            Case $filter_msg = $CLOSE
                ExitLoop
            Case $filter_msg = $GUI_EVENT_PRIMARYDOWN
                $win_state = WinGetState($Filter_Window)
                If BitAND($win_state, 8) And BitAND($win_state, 2) Then
                    If _GUICtrlListViewGetCurSel ($lv_filters) <> $LV_ERR Then
                        GUICtrlSetState($Delete, $GUI_ENABLE)
                    EndIf
                EndIf
        EndSelect
    Until $filter_msg = $GUI_EVENT_CLOSE
    GUIDelete($Filter_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigFilters

Func _ConfigIpRange(ByRef $a_IPRange, ByRef $Use_IPRange, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state, $ip, $nCurEdit = 0, $ip_tmp
    Local $lv_filters, $s_filter, $x, $filter_input[5], $filter_use, $Add, $Delete, $ip_len, $current_control
    $Filter_Window = GUICreate("IP Range Config", 360, 220, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel('Range(s) of IP Filter', 20, 10, 250, 20)
    $lv_filters = GUICtrlCreateListView("Start|End", 20, 40, 140, 140, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    _GUICtrlListViewSetColumnWidth ($lv_filters, 0, 90)
    If IsArray($a_IPRange) Then
        For $x = 1 To $a_IPRange[0]
            $s_filter = StringReplace($a_IPRange[$x], "-", "|")
            GUICtrlCreateListViewItem($s_filter, $lv_filters)
        Next
    EndIf
    $filter_use = GUICtrlCreateCheckbox("Use IP Range Inclusion Filter(s)", 170, 40)
    If $Use_IPRange Then GUICtrlSetState($filter_use, $GUI_CHECKED)
    
    $filter_input[0] = GUICtrlCreateInput("", 170, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[0], 3, 1)
    $filter_input[1] = GUICtrlCreateInput("", 205, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[1], 3, 1)
    $filter_input[2] = GUICtrlCreateInput("", 240, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[2], 3, 1)
    $filter_input[3] = GUICtrlCreateInput("", 275, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[3], 3, 1)
    GUICtrlCreateLabel("-", 310, 70, 10, 20)
    $filter_input[4] = GUICtrlCreateInput("", 320, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[4], 3, 1)
    $Add = GUICtrlCreateButton("Add", 170, 100, 120, 25)
    GUICtrlSetState($Add, $GUI_DISABLE)
    $Delete = GUICtrlCreateButton("Delete", 170, 130, 120, 25)
    GUICtrlSetState($Delete, $GUI_DISABLE)
    $Save = GUICtrlCreateButton("Save", 50, 190, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 190, 190, 120, 25)
    GUISetState()
    GUICtrlSetState($filter_input[0], $GUI_FOCUS)
    Do
        $filter_msg = GUIGetMsg()
        $ip = _IsPressedMod()
        If $ip > 0 Then
            $ip_tmp = GUICtrlRead($filter_input[$nCurEdit])
            If (StringLen($ip_tmp) = 3) And not ($ip = 8) Then
                If $nCurEdit = UBound($filter_input) - 1 Then ContinueLoop
                $nCurEdit = $nCurEdit + 1
                GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS)
            ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then
                If $nCurEdit = 0 Then ContinueLoop
                $nCurEdit = $nCurEdit - 1
                Sleep ( 200 ) ; make sure buffer clears
                GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($filter_input[$nCurEdit], GUICtrlRead($filter_input[$nCurEdit]))
            EndIf
        EndIf
        ; set current selection in case user hit tab key or used mouse to select input
        $current_control = ControlGetFocus($Filter_Window)
        Select
            Case $current_control = "Edit1" And $nCurEdit > 0
                $nCurEdit = 0
            Case $current_control = "Edit2" And $nCurEdit <> 1
                $nCurEdit = 1
            Case $current_control = "Edit3" And $nCurEdit <> 2
                $nCurEdit = 2
            Case $current_control = "Edit4" And $nCurEdit <> 3
                $nCurEdit = 3
            Case $current_control = "Edit5" And $nCurEdit < 4
                $nCurEdit = 4
        EndSelect

        Select
            Case $filter_msg = $Save
                If BitAND(GUICtrlRead($filter_use), $GUI_CHECKED) Then
                    $Use_IPRange = 1
                Else
                    $Use_IPRange = 0
                EndIf
                IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Filter", "Use", $Use_IPRange)
                IniDelete(@ScriptDir & '\AdminTool.ini', "IP-Ranges")
                If _GUICtrlListViewGetItemCount ($lv_filters) > 0 Then
                    ReDim $a_IPRange[_GUICtrlListViewGetItemCount ($lv_filters) + 1]
                    $a_IPRange[0] = _GUICtrlListViewGetItemCount ($lv_filters)
                    For $x = 0 To _GUICtrlListViewGetItemCount ($lv_filters) - 1
                        $a_IPRange[$x + 1] = StringReplace(_GUICtrlListViewGetItemText ($lv_filters, $x), "|", "-")
                        IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Ranges", "Range" & $x + 1, $a_IPRange[$x + 1])
                    Next
                Else
                    $a_IPRange = ""
                EndIf
            Case $filter_msg = $Delete
                _GUICtrlListViewDeleteItemsSelected ($lv_filters)
                GUICtrlSetState($Delete, $GUI_DISABLE)
            Case $filter_msg = $Add
                $ip = ""
                For $x = 0 To 3
                    $ip = $ip & GUICtrlRead($filter_input[$x]) & "."
                Next
                $ip = StringTrimRight($ip, 1)
                GUICtrlCreateListViewItem($ip & "|" & GUICtrlRead($filter_input[4]), $lv_filters)
                For $x = 0 To 4
                    GUICtrlSetData($filter_input[$x], "")
                Next
                ;***********************************
                $nCurEdit = 0
                ;***********************************
            Case $filter_msg = $CLOSE
                ExitLoop
            Case $filter_msg = $GUI_EVENT_PRIMARYDOWN
                $win_state = WinGetState($Filter_Window)
                If BitAND($win_state, 8) And BitAND($win_state, 2) Then
                    If _GUICtrlListViewGetCurSel ($lv_filters) <> $LV_ERR Then
                        GUICtrlSetState($Delete, $GUI_ENABLE)
                    EndIf
                EndIf
        EndSelect
        $ip_len = True
        For $x = 0 To 4
            If StringLen(GUICtrlRead($filter_input[$x])) == 0 Then
                $ip_len = False
                If ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_DISABLE)
                ExitLoop
            EndIf
        Next
        If $ip_len And Not ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_ENABLE)
    Until $filter_msg = $GUI_EVENT_CLOSE
    GUIDelete($Filter_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigIpRange

Func _IsPressedMod()
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 128
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc   ;==>_IsPressedMod

Func _GetIPRanges($IniFile, ByRef $IP_Range)
    Local $Ranges = IniReadSection($IniFile, "IP-Ranges"), $x
    If Not @error Then
        Dim $IP_Range[$Ranges[0][0] + 1]
        $IP_Range[0] = $Ranges[0][0]
        For $x = 1 To $Ranges[0][0]
            $IP_Range[$x] = $Ranges[$x][1]
        Next
    EndIf
EndFunc   ;==>_GetIPRanges

Func _ReduceMemory()
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

Func _LockAndWait()
    GUISetState(@SW_LOCK)
    
EndFunc   ;==>_LockAndWait

Func _ResetLockWait()
    GUISetState(@SW_UNLOCK)
    GUISetCursor($Cursor_ARROW, 1)
    _ReduceMemory()
EndFunc   ;==>_ResetLockWait
Link to comment
Share on other sites

This:

#NoTrayIcon
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Inet.au3>
#include <Constants.au3>

Global Const $Cursor_ARROW = 2
Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20
Global $Button_1
Global $Button_2
Global $msg

Opt('MustDeclareVars', 1)
Opt("GUIResizeMode", 1)

GUICreate("My GUI Button"); will create a dialog box that when displayed is centered

Opt("GUICoordMode", 2)
$Button_1 = GUICtrlCreateButton("LDAP Req", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("Button Test", 0, -1)

GUISetState()    ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            MsgBox (0, 'Testing', 'Button 1 was pressed')
        Case $msg = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')   ; Will demonstrate Button 2 being pressed
    EndSelect
WEnd

You have used MustDeclareVars option 1. If this option is used then all variables must be pre-declared with Dim, Local or Global before they can be used - removes the chance for misspelled variables causing bugs.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...