Sign in to follow this  
Followers 0
kasuya

PING + PROGRESS BAR

10 posts in this topic

Good day guys. I'm just learning autoit and i need your help in making a progress bar to ping a computer using stdreadout. The progress bar will continue to run until a certain site will reply when pinged. What i mean is that when you ping a website using command prompt, the script will read the phrase "Reply from" and would automatically stop and will post a message confirming that the site is alive. I have a vb script that does this but it doesn't have a GUI or progress bar. here is my vb scipt code:

While Not Connected

strTarget = "www.google.com"

Set objShell = CreateObject("WScript.Shell")

Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)

strPingResults = LCase(objExec.StdOut.ReadAll)

If InStr(strPingResults, "reply from") Then

Connected=True

End If

Wend

Thanks.

Share this post


Link to post
Share on other sites



2 requests and a delay of 1 sec

it's a bit short for a progress bar...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks for the reply wakillon. I was able to make a script. The progress bar is working but it still runs even though there is a response when I ping google through command prompt. Here is my script:

#include <Constants.au3>

$sLocation = "www.google.com"

Dim $Prog
Dim $ProgMax
Dim $Wait

$ProgMax = 500
$Wait = 1

$Process = Run (@ComSpec & " /c ping -n 100 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

ProgressOn ("PINGER","","")

While 1
    $Read = StdoutRead ($Process)
    If @error Then ExitLoop
    If not StringInStr ($Read, 'Reply from') then
        For $Prog = 1 to $ProgMax
        ProgressSet(($Prog/$ProgMax)*100,"","Checking WEBSITE availability")
        Sleep($Wait * 1000)
        Next
    Else
        msgBox(4096, "SUCCESS", "The SERVER Replied", 0)
    EndIf
        Sleep(10)
WEnd
    
ProgressOff()

Please guide me here. :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok try like this :

#include <Constants.au3>

$sLocation = "www.google.com"

Dim $Prog
Dim $ProgMax
Dim $Wait

$ProgMax = 500
$Wait = 1

$Process = Run ( @ComSpec & " /c ping -n 100 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProgressOn ("PINGER","","")

While 1
    $Read = StdoutRead ($Process)
    If @error Then ExitLoop
    If StringInStr ($Read, 'Reply from' ) = 0  Then 
        $Prog = $Prog + 1
        ProgressSet ( $Prog, "", "Checking WEBSITE availability" )
        Sleep ( $Wait * 100 )
    Else
        ProgressOff()
        While ProcessExists ( 'Ping.exe' )
            ProcessClose ( 'Ping.exe' )
        WEnd
        msgBox(4096, "SUCCESS", "The SERVER Replied", 0)
        ExitLoop
    EndIf
    Sleep(10)
WEnd

but i'll let you set progress limit ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks for the code wakillon. Still have a problem.:) The script or the progress bar doesnt run when the server doesnt respond or reply when pinged.. It seems that autoit automatically exits. got any idea?

Share this post


Link to post
Share on other sites

I tried replacing /c with /k but autoit exits and cmd.exe stays on the background.

$Process = Run ( @ComSpec & " /k ping -n 100 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Share this post


Link to post
Share on other sites

Try this

#include <Constants.au3>

$sLocation = "www.googlle.com"

Dim $Prog
Dim $ProgMax
Dim $Wait

$ProgMax = 500
$Wait = 1

$Process = Run ( @ComSpec & " /c ping -n 100 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProgressOn ("PINGER","","")

While ProcessExists ( $Process )
    $Read = StdoutRead ($Process)
    If Not @error Then
        If $Read Then ConsoleWrite ( "$Read : " & $Read & @Crlf ) ; when it write that it's time out you should exitloop
        If StringInStr ($Read, 'Reply from' ) = 0  Then
            $Prog = $Prog + 1
            ProgressSet ( $Prog, "", "Checking WEBSITE availability" )
            Sleep ( $Wait * 100 )
        Else
            ProgressOff()
            While ProcessExists ( 'Ping.exe' )
                ProcessClose ( 'Ping.exe' )
            WEnd
            msgBox(4096, "SUCCESS", "The SERVER Replied", 0)
            ExitLoop
        EndIf
    EndIf
    Sleep(10)
WEnd

But mine speak french, i can't give you the english words that you will find for "time out" Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Why not simply use the built-in Ping command straight from AutoIt and read the return from it to determine if you're connected or not? It's a lot simpler than trying to determine it from reading the StdReadOut from a command.

Or you could use the _GetIP command and see if it returns an IP address or not, if you're not connected to the internet then _GetIP will probably return -1 instead.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Why not simply use the built-in Ping command straight from AutoIt and read the return from it to determine if you're connected or not? It's a lot simpler than trying to determine it from reading the StdReadOut from a command.

Or you could use the _GetIP command and see if it returns an IP address or not, if you're not connected to the internet then _GetIP will probably return -1 instead.

@'BrewManNH

He simply want a progress bar while waiting for ping request result...Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

@'BrewManNH

He simply want a progress bar while waiting for ping request result...Posted Image

Then what should be done is check it using the Ping() command and use a marquee style progress bar, because using a regular progress bar doesn't work well if you don't know how long you're going to wait. Or he could use the handy-dandy progressbar UDF I have linked in my signature.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
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
Sign in to follow this  
Followers 0