PowNoob Posted August 31, 2010 Posted August 31, 2010 (edited) i did a search on here and google but with no success i'm trying to loop a "For" statement, see blowFor $i = 1if endifNextI tried and nothing happen while 1For $i = 1if endifNextwend Edited August 31, 2010 by PowNoob
JohnOne Posted August 31, 2010 Posted August 31, 2010 You did not search very far http://www.autoitscript.com/autoit3/docs/intro/lang_loops.htm AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
PowNoob Posted August 31, 2010 Author Posted August 31, 2010 here's is a copy of the script i found on this forum and i would like to modify to fit my needs what i want to do is have the scrip loop endless Dim $Host = "your host here" Dim $host_is_active = "No" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(10) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then MsgBox(1,1,"Host is active") $host_is_active = "Yes" EndIf If $i = $NetstatOutput[0]-1 AND $host_is_active <> "Yes" Then MsgBox(1,1,"Host isn't active - Rebooting") ;Shutdown(6) EndIf Next
PowNoob Posted September 2, 2010 Author Posted September 2, 2010 tried and not able to get it to loop.. it seem like it got stuck in a loop or something.. the same message comes on after the host has been disconnect.
JohnOne Posted September 2, 2010 Posted September 2, 2010 tried and not able to get it to loop..Show what you tried. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
PowNoob Posted September 2, 2010 Author Posted September 2, 2010 (edited) see blow i want to continue check for host with a loop Dim $Host = "host" Dim $host_is_active = "No" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(30) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) while 1 For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then ToolTip("Connected ^^", 2, 0) $host_is_active = "Yes" sleep(30) EndIf If $i = $NetstatOutput[0]-1 AND $host_is_active <> "Yes" Then ToolTip("Restarting", 2, 0) sleep(9000) EndIf Next WEnd Edited September 2, 2010 by PowNoob
4Eyes Posted September 2, 2010 Posted September 2, 2010 PowNoob, Mod'ing your code slightly like this... Dim $Host = "mikespc" ; Set to find my pc Dim $host_is_active = "No" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(30) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) ConsoleWrite("here" & @CRLF) ; At least I know got thru 1st loop ;while 1 For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then ConsoleWrite("Connected..." & @CRLF) ; Show that host has been found ToolTip("Connected ^^", 2, 0) $host_is_active = "Yes" sleep(30) EndIf If $i = $NetstatOutput[0]-1 AND $host_is_active <> "Yes" Then ToolTip("Restarting", 2, 0) sleep(9000) EndIf Next ;WEnd ...shows that it finds my pc if I set $Host = to the name of the pc I'm working on. It seems to me you'd be MUCH better off just pinging the host with either a known IP address or by name. That will be a lot faster. 4Eyes
PowNoob Posted September 2, 2010 Author Posted September 2, 2010 4Eyes, i was able to get through on first loop as well, my goal is to loop every time after sleep () BTW thanks ^^ i tried and still only loop once
PowNoob Posted September 4, 2010 Author Posted September 4, 2010 anyone know how to continue looping this? run cmd get ip and compare again after each loop, i was able to get everything in one loop but i want it to continue with infinite loop i really need some tips or help on this.. thanks
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