Jump to content

Recommended Posts

Posted (edited)

i did a search on here and google but with no success

i'm trying to loop a "For" statement, see blow

For $i = 1

if

endif

Next

I tried and nothing happen ;)

while 1

For $i = 1

if

endif

Next

wend

Edited by PowNoob
Posted

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

Posted

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.

Posted (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 by PowNoob
Posted

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

Posted

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

Posted

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

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...