Jump to content

Recommended Posts

Posted

Is there any way to interrupt a ping loop with button click.

I tried "GUICtrlSetOnEvent" & "WM_COMMAND" with no success.

Here where I got.

#include <Date.au3>
#include <File.au3>
#Include <GuiButton.au3>
#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt ("GUICloseOnESC", 1)
Opt ("GUIOnEventMode", 1)
Opt ("MustDeclareVars", 1)

Global $hGUIWin, $hStartIPAddress, $hEndIPAddress, $Start, $Stop, $Exit, $Interrupt = False
Global $aStartIP [4] = [10, 10, 64, 0], $aEndIP [4] = [10, 10, 95, 255]

$hGUIWin = GUICreate ("Workstation Installation Tool", 550, 125, -1, -1)
GUISetOnEvent ($GUI_EVENT_CLOSE, "Event", $hGUIWin)

GUICtrlCreateGroup ("Start IP:", 80, 5, 145, 50)
$hStartIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 100, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hStartIPAddress, $aStartIP)
_GUICtrlIpAddress_SetFocus ($hStartIPAddress, 2)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 2, 64, 95)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 3, 6, 254)

GUICtrlCreateGroup ("End IP:", 250, 5)
$hEndIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 270, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hEndIPAddress, $aEndIP)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 2, 64, 95)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 3, 6, 254)

$Start = GUICtrlCreateButton ("&Start", 430, 20, 110, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent ($Start, "Event")

$Exit = GUICtrlCreateButton ("&Exit", 430, 60, 110, 25)
GUICtrlSetOnEvent ($Exit, "Event")

GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

GUISetState (@SW_SHOW, $hGUIWin)

While 1
    Sleep (100)
WEnd

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Event ()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            If CheckIP () Then
                GUICtrlDelete ($Start)
                $Stop = GUICtrlCreateButton ("&Stop", 430, 20, 110, 25)
                GUICtrlSetOnEvent ($Stop, "Event")
                Install ()
                GUICtrlDelete ($Stop)
                $Start = GUICtrlCreateButton ("&Start", 430, 20, 110, 25)
                GUICtrlSetOnEvent ($Start, "Event")
            EndIf
        Case $Stop
            Exit
        Case $Exit
            Exit
    EndSwitch
EndFunc;==>Event

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func CheckIP ()
    $aStartIP = _GUICtrlIpAddress_GetArray ($hStartIPAddress)
    $aEndIP = _GUICtrlIpAddress_GetArray ($hEndIPAddress)
    If $aStartIP [2] > $aEndIP [2] Then
        Return False
    ElseIf $aStartIP [2] = $aEndIP [2] Then
        If $aStartIP [3] > $aEndIP [3] Then
            Return False
        Else
            Return True
        EndIf
    Else
        Return True
    EndIf
EndFunc;==>CheckIP

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Install ()
    Local $PCName
    Dim $WorkIP = $aStartIP
    Do
        Do
            If $Interrupt Then
                $Interrupt = False
                Return
            EndIf
            If $WorkIP [2] = $aEndIP [2] And $WorkIP [3] > $aEndIP [3] Then
                ExitLoop
            EndIf
            Local $PCIP = $WorkIP [0] & "." & $WorkIP [1] & "." & $WorkIP [2] & "." & $WorkIP [3]
            If Ping ($PCIP, 250) Then
                $PCName = RegRead ("\\" & $PCIP & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
            EndIf
            $WorkIP [3] += 1
        Until $WorkIP [3] > 254
        $WorkIP [3] = 6
        $WorkIP [2] += 1
    Until $WorkIP [2] > $aEndIP [2]
EndFunc;==>Install

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func WM_COMMAND ($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg
    Local $nNotifyCode = BitShift ($wParam, 16)
    Local $hCtrl = $lParam
    
    Switch $hCtrl
        Case $Stop
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $Interrupt = True
            EndSwitch
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_COMMAND
Posted (edited)

Inside the called function set the value of $Interrupt = True

That's a good solution. But, I like to quit the loop by pushing the button "$Stop". Is there anyway to do that?

Edited by all
Posted

You've built your script OnEventMode but with a quite "unusual" format so it wasn't so easy to do what you wanted.

I've rewritten a part of your script and got rid of your Event() function; I've created a couple new functions, got rid of the part deleting/creating buttons and it works in this form.

Have a look at IP limits because I've changed some of them to suit my needs.

#include <Date.au3>
#include <File.au3>
#Include <GuiButton.au3>
#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt ("GUICloseOnESC", 1)
Opt ("GUIOnEventMode", 1)
Opt ("MustDeclareVars", 1)



Global $hGUIWin, $hStartIPAddress, $hEndIPAddress, $Start, $Stop, $Exit, $Interrupt = False
Global $aStartIP [4] = [10, 10, 64, 0], $aEndIP [4] = [10, 10, 95, 255]

$hGUIWin = GUICreate ("Workstation Installation Tool", 550, 125, -1, -1)
GUISetOnEvent ($GUI_EVENT_CLOSE, "Close", $hGUIWin)

GUICtrlCreateGroup ("Start IP:", 80, 5, 145, 50)
$hStartIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 100, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hStartIPAddress, $aStartIP)
_GUICtrlIpAddress_SetFocus ($hStartIPAddress, 2)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 3, 6, 254)

GUICtrlCreateGroup ("End IP:", 250, 5)
$hEndIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 270, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hEndIPAddress, $aEndIP)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 3, 6, 254)

$Start = GUICtrlCreateButton ("&Start", 430, 20, 110, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent ($Start, "Start")

$Exit = GUICtrlCreateButton ("&Exit", 430, 60, 110, 25)
GUICtrlSetOnEvent ($Exit, "Close")

GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

GUISetState (@SW_SHOW, $hGUIWin)

While 1
    Sleep (100)
WEnd

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func setInterrupt()         ;changes the value of your flag
    MsgBox(0, "", "stopped")
    $Interrupt = True
EndFunc

Func Close()        ;new function to handle the Exit event
    Exit
EndFunc

Func Start()        ;new function to handle the pressing of $start button
    Switch @GUI_CtrlId
        Case $Start
            If GUICtrlRead($Start) = "Stop" Then    ;if the text is "Stop" and the button was pressed
                setInterrupt()                      ;set the flag
                GUICtrlSetData($Start, "Start")     ;change the button text
            Else
                If CheckIP () Then
                    GUICtrlSetData($Start, "Stop")  ;set the text to "Stop"
                    Install ()                      ;do your work
                EndIf
            EndIf
    EndSwitch
EndFunc

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func CheckIP ()
    $aStartIP = _GUICtrlIpAddress_GetArray ($hStartIPAddress)
    $aEndIP = _GUICtrlIpAddress_GetArray ($hEndIPAddress)
    If $aStartIP [2] > $aEndIP [2] Then
        Return False
    ElseIf $aStartIP [2] = $aEndIP [2] Then
        If $aStartIP [3] > $aEndIP [3] Then
            Return False
        Else
            Return True
        EndIf
    Else
        Return True
    EndIf
EndFunc;==>CheckIP

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Install ()
    MsgBox(0, "", "started")
    Local $PCName
    Dim $WorkIP = $aStartIP
    Do
        Do
            If $Interrupt Then
                $Interrupt = False
                Return
            EndIf
            If $WorkIP [2] = $aEndIP [2] And $WorkIP [3] > $aEndIP [3] Then
                ExitLoop
            EndIf
            Local $PCIP = $WorkIP [0] & "." & $WorkIP [1] & "." & $WorkIP [2] & "." & $WorkIP [3]
            If Ping ($PCIP, 250) Then
                $PCName = RegRead ("\\" & $PCIP & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
            EndIf
            $WorkIP [3] += 1
        Until $WorkIP [3] > 254
        $WorkIP [3] = 6
        $WorkIP [2] += 1
    Until $WorkIP [2] > $aEndIP [2]
EndFunc;==>Install

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func WM_COMMAND ($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg
    Local $nNotifyCode = BitShift ($wParam, 16)
    Local $hCtrl = $lParam
    
    Switch $hCtrl
        Case $Stop
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $Interrupt = True
            EndSwitch
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_COMMAND

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

you have to hit "Esc" for the process to stop!!!

and afterwards the fun "Install" never get called

it got to be the interrupt call! (little bit confusing)

I removed the msgbox & add statusbar

#Include <GuiButton.au3>
#include <GuiStatusBar.au3>
#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt ("GUIOnEventMode", 1)
Opt ("MustDeclareVars", 1)

Global $aParts [2] = [500, -1]
Global $hGUIWin, $hStartIPAddress, $hEndIPAddress, $Start, $Stop, $Exit, $Interrupt = False, $hStatusBar
Global $aStartIP [4] = [10, 10, 64, 0], $aEndIP [4] = [10, 10, 95, 255]

$hGUIWin = GUICreate ("Workstation Installation Tool", 550, 125, -1, -1)
GUISetOnEvent ($GUI_EVENT_CLOSE, "Close", $hGUIWin)

GUICtrlCreateGroup ("Start IP:", 80, 5, 145, 50)
$hStartIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 100, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hStartIPAddress, $aStartIP)
_GUICtrlIpAddress_SetFocus ($hStartIPAddress, 2)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 3, 6, 254)

GUICtrlCreateGroup ("End IP:", 250, 5)
$hEndIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 270, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hEndIPAddress, $aEndIP)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 3, 6, 254)

$Start = GUICtrlCreateButton ("&Start", 430, 20, 110, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent ($Start, "Start")

$Exit = GUICtrlCreateButton ("&Exit", 430, 60, 110, 25)
GUICtrlSetOnEvent ($Exit, "Close")

$hStatusBar = _GUICtrlStatusBar_Create ($hGUIWin, $aParts)
_GUICtrlStatusBar_SetMinHeight ($hStatusBar, 22)

GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

GUISetState (@SW_SHOW, $hGUIWin)

While 1
    Sleep (100)
WEnd

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func SetInterrupt ()  ;changes the value of your flag
    $Interrupt = True
EndFunc;==>SetInterrupt

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Close ()      ;new function to handle the Exit event
    Exit
EndFunc;==>Close

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Start ()      ;new function to handle the pressing of $start button
    Switch @GUI_CtrlId
        Case $Start
            If GUICtrlRead ($Start) = "Stop" Then   ;if the text is "Stop" and the button was pressed
                SetInterrupt ()        ;set the flag
                GUICtrlSetData ($Start, "Start") ;change the button text
            Else
                If CheckIP () Then
                    GUICtrlSetData ($Start, "Stop") ;set the text to "Stop"
                    Install ()         ;do your work
                EndIf
            EndIf
    EndSwitch
EndFunc;==>Start

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func CheckIP ()
    $aStartIP = _GUICtrlIpAddress_GetArray ($hStartIPAddress)
    $aEndIP = _GUICtrlIpAddress_GetArray ($hEndIPAddress)
    If $aStartIP [2] > $aEndIP [2] Then
        Return False
    ElseIf $aStartIP [2] = $aEndIP [2] Then
        If $aStartIP [3] > $aEndIP [3] Then
            Return False
        Else
            Return True
        EndIf
    Else
        Return True
    EndIf
EndFunc;==>CheckIP

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Install ()
    Local $PCName
    Dim $WorkIP = $aStartIP
    Do
        Do
            If $Interrupt Then
                $Interrupt = False
                Return
            EndIf
            If $WorkIP [2] = $aEndIP [2] And $WorkIP [3] > $aEndIP [3] Then
                ExitLoop
            EndIf
            Local $PCIP = $WorkIP [0] & "." & $WorkIP [1] & "." & $WorkIP [2] & "." & $WorkIP [3]
            _GUICtrlStatusBar_SetText ($hStatusBar, " Pinging IP: " & $PCIP)
            If Ping ($PCIP, 250) Then
                $PCName = RegRead ("\\" & $PCIP & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
            EndIf
            $WorkIP [3] += 1
        Until $WorkIP [3] > 254
        $WorkIP [3] = 6
        $WorkIP [2] += 1
    Until $WorkIP [2] > $aEndIP [2]
EndFunc;==>Install

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func WM_COMMAND ($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg
    Local $nNotifyCode = BitShift ($wParam, 16)
    Local $hCtrl = $lParam
   
    Switch $hCtrl
        Case $Stop
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $Interrupt = True
            EndSwitch
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_COMMAND
Posted

Sorry ... you're right ...

I've tested the script with a small IP range and I thought it worked ...

Anyway I give up - I tried today for more than 2 hours to make this script work and no success.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

OK - with BIG THANKS to rasim and newbiescripter ... here is the working result of your script:

#Include <GuiButton.au3>
#include <GuiStatusBar.au3>
#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt ("GUIOnEventMode", 1)
Opt ("MustDeclareVars", 1)

Global $aParts [2] = [500, -1]
Global $hGUIWin, $hStartIPAddress, $hEndIPAddress, $Start, $Stop, $Exit, $Interrupt = True, $hStatusBar
Global $aStartIP [4] = [10, 10, 64, 0], $aEndIP [4] = [10, 10, 95, 255]

$hGUIWin = GUICreate ("Workstation Installation Tool", 550, 125, -1, -1)
GUISetOnEvent ($GUI_EVENT_CLOSE, "Close", $hGUIWin)

GUICtrlCreateGroup ("Start IP:", 80, 5, 145, 50)
$hStartIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 100, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hStartIPAddress, $aStartIP)
_GUICtrlIpAddress_SetFocus ($hStartIPAddress, 2)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hStartIPAddress, 3, 6, 254)

GUICtrlCreateGroup ("End IP:", 250, 5)
$hEndIPAddress = _GUICtrlIpAddress_Create ($hGUIWin, 270, 26, 100, 18)
_GUICtrlIpAddress_SetArray ($hEndIPAddress, $aEndIP)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 2, 64, 200)
_GUICtrlIpAddress_SetRange ($hEndIPAddress, 3, 6, 254)

$Start = GUICtrlCreateButton ("&Start", 430, 20, 110, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent ($Start, "Start")

$Exit = GUICtrlCreateButton ("&Exit", 430, 60, 110, 25)
GUICtrlSetOnEvent ($Exit, "Close")

$hStatusBar = _GUICtrlStatusBar_Create ($hGUIWin, $aParts)
_GUICtrlStatusBar_SetMinHeight ($hStatusBar, 22)

GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

GUISetState (@SW_SHOW, $hGUIWin)

While 1
    Sleep (100)
WEnd

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Close ()       ;new function to handle the Exit event
    Exit
EndFunc;==>Close

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Start ()       ;new function to handle the pressing of $start button
    If GUICtrlRead ($Start) = "Stop" Then   ;if the text is "Stop" and the button was pressed
        GUICtrlSetData ($Start, "Start") ;change the button text
    Else
        If CheckIP () Then
            GUICtrlSetData ($Start, "Stop") ;set the text to "Stop"
            Install ()           ;do your work
        EndIf
    EndIf
EndFunc;==>Start

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func CheckIP ()
    $aStartIP = _GUICtrlIpAddress_GetArray ($hStartIPAddress)
    $aEndIP = _GUICtrlIpAddress_GetArray ($hEndIPAddress)
    If $aStartIP [2] > $aEndIP [2] Then
        Return False
    ElseIf $aStartIP [2] = $aEndIP [2] Then
        If $aStartIP [3] > $aEndIP [3] Then
            Return False
        Else
            Return True
        EndIf
    Else
        Return True
    EndIf
EndFunc;==>CheckIP

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func Install ()
    Local $PCName
    Dim $WorkIP = $aStartIP
    Do
        Do
            If $Interrupt Then Return
            If $WorkIP [2] = $aEndIP [2] And $WorkIP [3] > $aEndIP [3] Then
                ExitLoop
            EndIf
            Local $PCIP = $WorkIP [0] & "." & $WorkIP [1] & "." & $WorkIP [2] & "." & $WorkIP [3]
            _GUICtrlStatusBar_SetText ($hStatusBar, " Pinging IP: " & $PCIP)
            If Ping ($PCIP, 250) Then
                $PCName = RegRead ("\\" & $PCIP & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")
            EndIf
            $WorkIP [3] += 1
        Until $WorkIP [3] > 254
        $WorkIP [3] = 6
        $WorkIP [2] += 1
    Until $WorkIP [2] > $aEndIP [2]
EndFunc;==>Install

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Func WM_COMMAND ($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ;LoWord
    Local $iCode = BitShift($wParam, 16) ;HiWord
    
    Switch $iIDFrom
        Case $Start
            Switch $iCode
                Case $BN_CLICKED
                    $Interrupt = Not $Interrupt
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_COMMAND

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

Thanx a lot muttley

Two more Qs: Why it quits with the Esc key (strange behavior), without declaring "GUICloseOnESC"?

Can U explain whats all about the "LoWord" & "HiWord" thing?

TIA

Posted

I don't know why it exits when pressing Esc - I guess it is related to using GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

About your second question: no idea either - I haven't read about this function yet. Rasim can explain this to you muttley

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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
  • Recently Browsing   0 members

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