jezr74 Posted June 29, 2005 Share Posted June 29, 2005 Hi there, A quick question If I may, is there a command for returning to the start of a script in AutoIT. I am fairly new to this and am unable to find anthing of the like after looking through the forums and helpfiles as far as an answer. I have been teaching myself the basics by using scripts members have posted, and trying to understand them and make changes. With this ping script that uses ICMP, I'm trying to make it return to the start if "Ok" is pressed. but cannot work out how... this was a good test script for me because it does'nt use raw sockets... $pinger = InputBox("ICMP Pinger","Enter IP Address or Machine Name:","localhost"," 25","200","125","400","-1") RunWait(@ComSpec & " /C Ping -a -n 1 " & $pinger & "> PingResults.txt",@UserProfileDir, @SW_HIDE) $pinger = FileRead(@UserProfileDir & "\PingResults.txt", FileGetSize(@UserProfileDir & "\PingResults.txt")) FileDelete(@UserProfileDir & "\PingResults.txt") $PingResults = MsgBox(1,"ICMP Pinger Results", "" & $pinger) if $PingResults = 1 Then ??? goto start? <--- is there something here I can put to go back to the start? Exit Thanks in advance, jtsm Link to comment Share on other sites More sharing options...
GaryFrost Posted June 29, 2005 Share Posted June 29, 2005 (edited) $pinger = InputBox("ICMP Pinger", "Enter IP Address or Machine Name:", "localhost", " 25", "200", "125", "400", "-1") If @error Then Exit Do RunWait(@ComSpec & " /C Ping -a -n 1 " & $pinger & "> PingResults.txt", @UserProfileDir, @SW_HIDE) $pinged = FileRead(@UserProfileDir & "\PingResults.txt", FileGetSize(@UserProfileDir & "\PingResults.txt")) FileDelete(@UserProfileDir & "\PingResults.txt") $PingResults = MsgBox(1, "ICMP Pinger Results", "" & $pinged) Until $PingResults <> 1 $pinged read from file, changed from $pinger, overwrote ip/machine name Edited June 29, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jezr74 Posted June 29, 2005 Author Share Posted June 29, 2005 Thanks for the fast reply. Is there a way to make it return to put in a new host name if needed? I ran your suggestion and pressing ok on the results window will re-fresh that screen, can it "refresh" back to the inital screen, and give the option to type in a new host name if needed? or would i need to some how incorporatate the inputbox and results into a single window? Link to comment Share on other sites More sharing options...
GaryFrost Posted June 29, 2005 Share Posted June 29, 2005 Do $pinger = InputBox("ICMP Pinger", "Enter IP Address or Machine Name:", "localhost", " 25", "200", "125", "400", "-1") If @error Then Exit RunWait(@ComSpec & " /C Ping -a -n 1 " & $pinger & "> PingResults.txt", @UserProfileDir, @SW_HIDE) $pinged = FileRead(@UserProfileDir & "\PingResults.txt", FileGetSize(@UserProfileDir & "\PingResults.txt")) FileDelete(@UserProfileDir & "\PingResults.txt") $PingResults = MsgBox(1, "ICMP Pinger Results", "" & $pinged) Until $PingResults <> 1 SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jezr74 Posted June 29, 2005 Author Share Posted June 29, 2005 Nice, Thanks for your help. Link to comment Share on other sites More sharing options...
GaryFrost Posted June 29, 2005 Share Posted June 29, 2005 (edited) for autoit 3.1.1 Heres a GUI version of it Something for you to look at. expandcollapse popup#include <GuiConstants.au3> AutoItSetOption("ProvideRunStdout", 1) GuiCreate("Pinger", 483, 322) $host = "localhost" $ping_results = GuiCtrlCreateLabel("", 20, 20, 320, 290,$SS_SUNKEN ) GuiCtrlCreateLabel("IP Address or Machine Name", 360, 10, 100, 30) $input_host = GuiCtrlCreateInput($host, 360, 40, 110, 20) GuiCtrlCreateLabel("Interval (seconds)", 360, 80, 100, 20) $input_interval = GuiCtrlCreateInput("3", 360, 110, 110, 20,$ES_NUMBER) $Btn_Ping = GuiCtrlCreateButton("Start", 360, 150, 100, 30) $Btn_Stop = GuiCtrlCreateButton("Stop", 360, 200, 100, 30) $Bt_Exit = GuiCtrlCreateButton("Exit", 360, 250, 100, 30) $interval = Int(GUICtrlRead($input_interval)) * 1000 GuiSetState() $pinging = 0 While 1 $msg = GuiGetMsg() If Int(GUICtrlRead($input_interval)) * 1000 <> $interval And $pinging Then $interval = Int(GUICtrlRead($input_interval)) * 1000 $host = GUICtrlRead($input_host) AdlibDisable ( ) AdlibEnable("_PingIT",$interval) EndIf Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Bt_Exit ExitLoop Case $msg = $Btn_Ping $pinging = 1 $interval = Int(GUICtrlRead($input_interval)) * 1000 $host = GUICtrlRead($input_host) _PingIT() AdlibEnable("_PingIT",$interval) Case $msg = $Btn_Stop $pinging = 0 AdlibDisable ( ) EndSelect WEnd Exit Func _PingIT() $results = @Hour & ":" & @MIN & ":" & @SEC & @LF $ping = Run(@ComSpec & " /C Ping -a -n 1 " & $host, "", @SW_HIDE) While 1 $line = StdoutRead($ping) If @error = -1 Then ExitLoop $results = $results & $line Wend GUICtrlSetData($ping_results,$results) EndFunc Edited June 29, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted June 29, 2005 Share Posted June 29, 2005 (edited) Beta version expandcollapse popup#include <Constants.au3> #include <GuiConstants.au3> GuiCreate("Pinger", 483, 322) $host = "localhost" $ping_results = GuiCtrlCreateLabel("", 20, 20, 320, 290,$SS_SUNKEN ) GuiCtrlCreateLabel("IP Address or Machine Name", 360, 10, 100, 30) $input_host = GuiCtrlCreateInput($host, 360, 40, 110, 20) GuiCtrlCreateLabel("Interval (seconds)", 360, 80, 100, 20) $input_interval = GuiCtrlCreateInput("3", 360, 110, 110, 20,$ES_NUMBER) $Btn_Ping = GuiCtrlCreateButton("Start", 360, 150, 100, 30) $Btn_Stop = GuiCtrlCreateButton("Stop", 360, 200, 100, 30) $Bt_Exit = GuiCtrlCreateButton("Exit", 360, 250, 100, 30) $interval = Int(GUICtrlRead($input_interval)) * 1000 GuiSetState() $pinging = 0 While 1 $msg = GuiGetMsg() If Int(GUICtrlRead($input_interval)) * 1000 <> $interval And $pinging Then $interval = Int(GUICtrlRead($input_interval)) * 1000 $host = GUICtrlRead($input_host) AdlibDisable ( ) AdlibEnable("_PingIT",$interval) EndIf Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Bt_Exit ExitLoop Case $msg = $Btn_Ping $pinging = 1 $interval = Int(GUICtrlRead($input_interval)) * 1000 $host = GUICtrlRead($input_host) _PingIT() AdlibEnable("_PingIT",$interval) Case $msg = $Btn_Stop $pinging = 0 AdlibDisable ( ) EndSelect WEnd Exit Func _PingIT() $results = @Hour & ":" & @MIN & ":" & @SEC & @LF $ping = Run(@ComSpec & " /C Ping -a -n 1 " & $host, "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($ping) If @error = -1 Then ExitLoop $results = $results & $line Wend GUICtrlSetData($ping_results,$results) EndFunc Edited June 29, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now