Jump to content
Sign in to follow this  
JoaoCampos

Need some help on ping stuff

Recommended Posts

JoaoCampos

Hello all, sorry for my noob questions but ive installed AutoIt3 today.

Well first of all here is my script:

;~ Get some var info from config file
$server = IniRead("config.ini", "General", "Server", "none" )
$showurl = IniRead("config.ini", "General", "Show", "none" )

$iepath = "c:\Program Files\Internet Explorer\iexplore.exe"

$checkiemode = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings', 'GlobalUserOffline')


;~ Loop check for server and execute different commands for each state
While 1
$servertest = Ping($server ,250)

;~ If server ping responds OK and, in the Registry Internet state is set to offline...
If $servertest & $checkiemode=1 Then;

    ;~ Set Internet explorer to Online Mode
    RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "0" )
    
    ;~ Run taskkill all Iexplorer process's
    Run("TASKKILL /F /IM iexplore.exe")
    
    ;~ Wait 1000 ms
    Sleep(1000)
    
    ;~ Start the show again
    ShellExecute($showurl)

;~ If server ping dont responds and, in the Registry Internet state is set to Online...
ElseIf $servertest & $checkiemode=0 Then;

    ;~ Set Internet explorer to Offline Mode
    RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "1" )

    ;~ Run taskkill all Iexplorer process's
    Run("TASKKILL /F /IM iexplore.exe")

    ;~ Wait 1000 ms
    Sleep(1000)

    ;~ Start the show again
    ShellExecute($showurl)

Else
EndIf
;~ Wait 5000 ms until next loop
Sleep(5000)
WEnd

My ini file is:

[General]

Server=prtn.zapto.org

Show=http://prtn.zapto.org/web/player

The idea is:

It executes a ping command,

if the ping commands responds ok AND in the registery we have offline mode, it sets Internet to onlinemode, Kills all iexplore.exe tasks, make some delay, and executes again iexplore with url running the page in online mode;

if the ping commands do not responds AND in the registery we have online mode, it sets Internet to offlinemode, Kills all iexplore.exe tasks, make some delay, and executes again iexplore with url running the page in offline mode from cache.

My problem is... i dont know how to tell in the elseif "ElseIf $servertest "dont responds" & $checkiemode=0 Then;".... if ping do not responds and mode is online.

Hope someone can help me on it.

Regards,

JC

Share this post


Link to post
Share on other sites
smashly

Hi,

If the server return is differant to 0 then the ping is working.

If $servertest <> 0 And $checkiemode = 1 ThenoÝ÷ Øíë®÷«­ën®x¬ÒØ^Ø^­íý±ªk¡¹^§)ඬz»Þ­«­¢+Ù±Í%ÀÌØíÍÉÙÉÑÍÐôÀ¹ÀÌØí¡­¥µ½ôÀQ¡¸

I've only briefly looked at your script..

But have a look in the help file under Language References-> Operators

Will post back a bit l8r if no 1 else has come along and helped in the meantime.

Cheers

Share this post


Link to post
Share on other sites
JoaoCampos

Hi,

If the server return is differant to 0 then the ping is working.

If $servertest <> 0 And $checkiemode = 1 ThenoÝ÷ Øíë®÷«­ën®x¬ÒØ^Ø^­íý±ªk¡¹^§)ඬz»Þ­«­¢+Ù±Í%ÀÌØíÍÉÙÉÑÍÐôÀ¹ÀÌØí¡­¥µ½ôÀQ¡¸oÝ÷ Øý½ê'&ëçåÊZ(çZ·*.®Ç+AºØZ½æ¥¢"Ø^éi~)^ºw^¬¶§æ yz·§që ´ê^­«h®Å¢Zh²ÖÚrFÙ|®'ç£W¥±èZ±Ê&y©h§v¥¥çbØ^槶)
®Ïêº^JazÇ+pY[zX¤zØb±«­¢+Ø(íøÐͽµÙÈ¥¹¼É½´½¹¥¥±(ÀÌØíÍÉÙÈô%¹¥I ÅÕ½Ðí½¹¥¹¥¹¤ÅÕ½Ðì°ÅÕ½Ðí¹É°ÅÕ½Ðì°ÅÕ½ÐíMÉÙÈÅÕ½Ðì°ÅÕ½Ðí¹½¹ÅÕ½Ðì¤(ÀÌØíÍ¡½ÝÕÉ°ô%¹¥I ÅÕ½Ðí½¹¥¹¥¹¤ÅÕ½Ðì°ÅÕ½Ðí¹É°ÅÕ½Ðì°ÅÕ½ÐíM¡½ÜÅÕ½Ðì°ÅÕ½Ðí¹½¹ÅÕ½Ðì¤((ÀÌØí¥ÁÑ ôÅÕ½ÐíèÀäÈíAɽɴ¥±ÌÀäÈí%¹ÑɹÐáÁ±½ÉÈÀäÈí¥áÁ±½É¹áÅÕ½Ðì((ÀÌØí¡­¥µ½ôII Ìäí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÌäì°Ìäí±½±UÍÉ=±¥¹Ìäì¤(((íø1½½À¡¬½ÈÍÉÙȹáÕѥɹнµµ¹Ì½È ÍÑÑ)]¡¥±Ä(ÀÌØíÍÉÙÉÑÍÐôA¥¹ ÀÌØíÍÉÙÈ°ÈÔÀ¤((íø%ÍÉÙÈÁ¥¹ÉÍÁ½¹Ì=,¹°¥¸Ñ¡I¥ÍÑÉä%¹ÑɹÐÍÑÑ¥ÌÍÐѼ½±¥¹¸¸¸)%ÀÌØíÍÉÙÉÑÍбÐìÐìÀ¹ÀÌØí¡­¥µ½ôÄQ¡¸(($íøMÐ%¹ÑɹÐáÁ±½ÉÈѼ=¹±¥¹5½(%I]É¥Ñ ÅÕ½Ðí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÅÕ½Ðì°ÅÕ½Ðí±½±UÍÉ=±¥¹ÅÕ½Ðì°ÅÕ½ÐíI}]=IÅÕ½Ðì°ÅÕ½ÐìÀÅÕ½Ðì¤($($íøIÕ¸ÑÍ­­¥±°±°%áÁ±½ÉÈÁɽÍÌÌäíÌ(%IÕ¸ ÅÕ½ÐíQM--%10½½%4¥áÁ±½É¹áÅÕ½Ðì¤($($íø]¥ÐÄÀÀÀµÌ(%M±À ÄÀÀÀ¤($($íøMÑÉÐÑ¡Í¡½Ü¥¸(%M¡±±áÕÑ ÀÌØíÍ¡½ÝÕÉ°¤((íø%ÍÉÙÈÁ¥¹½¹ÐÉÍÁ½¹Ì¹°¥¸Ñ¡I¥ÍÑÉä%¹ÑɹÐÍÑÑ¥ÌÍÐѼ=¹±¥¹¸¸¸)±Í%ÀÌØíÍÉÙÉÑÍÐôÀ¹ÀÌØí¡­¥µ½ôÀQ¡¸(($íøMÐ%¹ÑɹÐáÁ±½ÉÈѼ=±¥¹5½(%I]É¥Ñ ÅÕ½Ðí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÅÕ½Ðì°ÅÕ½Ðí±½±UÍÉ=±¥¹ÅÕ½Ðì°ÅÕ½ÐíI}]=IÅÕ½Ðì°ÅÕ½ÐìÄÅÕ½Ðì¤(($íøIÕ¸ÑÍ­­¥±°±°%áÁ±½ÉÈÁɽÍÌÌäíÌ(%IÕ¸ ÅÕ½ÐíQM--%10½½%4¥áÁ±½É¹áÅÕ½Ðì¤(($íø]¥ÐÄÀÀÀµÌ(%M±À ÄÀÀÀ¤(($íøMÑÉÐÑ¡Í¡½Ü¥¸(%M¡±±áÕÑ ÀÌØíÍ¡½ÝÕÉ°¤()±Í)¹%(íø]¥ÐÔÀÀÀµÌչѥ°¹áб½½À)M±À ÔÀÀÀ¤)]¹(

Ive made that and it isnt working :shocked:

Regards,

JC

Edited by JoaoCampos

Share this post


Link to post
Share on other sites
smashly

Yep the script can be like that :shocked:

But it does need some tweaking for it to work correctly.

Some other options for you to have a look at would be process management in the help file...

ProcessExists() and ProcessClose() This will do away with the ugly cmd window to kill IE.

eg:

If ProcessExists(iexplorer.exe) Then
    ProcessClose(iexplorer.exe)
EndIf

There are alot more elegant ways to do what I've said, but it's just a suggestion to get you started.

I don't use IE so I have a prob testing your script.

But when I run it I does do what is said for it to do, but it continues over and over...

I'll have a further look at it , but I'm in the middle of writing another script myself or should I say reworking some1 elses script for fun.

Edited by smashly

Share this post


Link to post
Share on other sites
JoaoCampos

Yep the script can be like that :shocked:

But it does need some tweaking for it to work correctly.

Some other options for you to have a look at would be process management in the help file...

ProcessExists() and ProcessClose() This will do away with the ugly cmd window to kill IE.

eg:

If ProcessExists(iexplorer.exe) Then
    ProcessClose(iexplorer.exe)
EndIfoÝ÷ Ù8^­æ«y©h¶j+^©íÁ¬¬¶h­#ozÆ¢u»­Ýý²;¬µ«.¬¶*'¶·*.²Ö«µçHv÷öÛ¬x, Z½æ©®ízËb¨º»®*mëpéÈ®éâ´hzÇh­Ë×è®+m¡ÚºØ­rí{²Þ­©Ý¢÷«#e¯y§î®Ø^®Z(«bµ»­#f{azhvW¨
â¶)àjz-êìr¸©¶l¬zWè®ÈhºWH±¬«{
+)à²ÕélzË®*m~ߺêº^N§Çè¯*.naaæ¡ØZ¦§²Ú&-êk¡¹^¬¶«zÚ®z¼°jÊ.¶ÈzØ^)êÞج)ÞÁÊy©ÝÂä³¥«­¢+Ø(íøÐͽµÙÈ¥¹¼É½´½¹¥¥±(ÀÌØíÍÉÙÈô%¹¥I ÅÕ½Ðí½¹¥¹¥¹¤ÅÕ½Ðì°ÅÕ½Ðí¹É°ÅÕ½Ðì°ÅÕ½ÐíMÉÙÈÅÕ½Ðì°ÅÕ½Ðí¹½¹ÅÕ½Ðì¤(ÀÌØíÍ¡½ÝÕÉ°ô%¹¥I ÅÕ½Ðí½¹¥¹¥¹¤ÅÕ½Ðì°ÅÕ½Ðí¹É°ÅÕ½Ðì°ÅÕ½ÐíM¡½ÜÅÕ½Ðì°ÅÕ½Ðí¹½¹ÅÕ½Ðì¤((ÀÌØí¥ÁÑ ôÅÕ½ÐíèÀäÈíAɽɴ¥±ÌÀäÈí%¹ÑɹÐáÁ±½ÉÈÀäÈí¥áÁ±½É¹áÅÕ½Ðì(((íø1½½À¡¬½ÈÍÉÙȹáÕѥɹнµµ¹Ì½È ÍÑÑ)]¡¥±Ä(ÀÌØíÍÉÙÉÑÍÐôA¥¹ ÀÌØíÍÉÙÈ°ÈÔÀ¤(ÀÌØí¡­¥µ½ôII Ìäí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÌäì°Ìäí±½±UÍÉ=±¥¹Ìäì¤((íø%ÍÉÙÈÁ¥¹ÉÍÁ½¹Ì=,¹°¥¸Ñ¡I¥ÍÑÉä%¹ÑɹÐÍÑÑ¥ÌÍÐѼ½±¥¹¸¸¸)%ÀÌØíÍÉÙÉÑÍбÐìÐìÀ¹ÀÌØí¡­¥µ½ôÄQ¡¸(($íøMÐ%¹ÑɹÐáÁ±½ÉÈѼ=¹±¥¹5½(%I]É¥Ñ ÅÕ½Ðí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÅÕ½Ðì°ÅÕ½Ðí±½±UÍÉ=±¥¹ÅÕ½Ðì°ÅÕ½ÐíI}]=IÅÕ½Ðì°ÅÕ½ÐìÀÅÕ½Ðì¤($($íøIÕ¸ÑÍ­­¥±°±°%áÁ±½ÉÈÁɽÍÌÌäíÌ(%IÕ¸ ÅÕ½ÐíQM--%10½½%4¥áÁ±½É¹áÅÕ½Ðì¤((($íø]¥ÐÄÀÀÀµÌ(%M±À ÄÀÀÀ¤($($íøMÑÉÐÑ¡Í¡½Ü¥¸(%M¡±±áÕÑ ÀÌØíÍ¡½ÝÕÉ°¤((íø%ÍÉÙÈÁ¥¹½¹ÐÉÍÁ½¹Ì¹°¥¸Ñ¡I¥ÍÑÉä%¹ÑɹÐÍÑÑ¥ÌÍÐѼ=¹±¥¹¸¸¸)±Í%ÀÌØíÍÉÙÉÑÍÐôÀ¹ÀÌØí¡­¥µ½ôÀQ¡¸(($íøMÐ%¹ÑɹÐáÁ±½ÉÈѼ=±¥¹5½(%I]É¥Ñ ÅÕ½Ðí!-e}
UII9Q}UMHÀäÈíM½ÑÝÉÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÀäÈí%¹ÑɹÐMÑÑ¥¹ÌÅÕ½Ðì°ÅÕ½Ðí±½±UÍÉ=±¥¹ÅÕ½Ðì°ÅÕ½ÐíI}]=IÅÕ½Ðì°ÅÕ½ÐìÄÅÕ½Ðì¤(($íøIÕ¸ÑÍ­­¥±°±°%áÁ±½ÉÈÁɽÍÌÌäíÌ(%IÕ¸ ÅÕ½ÐíQM--%10½½%4¥áÁ±½É¹áÅÕ½Ðì¤(($íø]¥ÐÄÀÀÀµÌ(%M±À ÄÀÀÀ¤(($íøMÑÉÐÑ¡Í¡½Ü¥¸(%M¡±±áÕÑ ÀÌØíÍ¡½ÝÕÉ°¤()±Í)¹%(íø]¥ÐÔÀÀÀµÌչѥ°¹áб½½À)M±À ÔÀÀÀ¤)]¹(((

Can you explain me how can i tweak it with your suggestion ?

Share this post


Link to post
Share on other sites
smashly

ProcessExist() , ProcessClose , ProcessWaitClose .. these functions can do away with the Run Task Kill and extra Sleep() your adding.

;~ Get some var info from config file
$server = IniRead("config.ini", "General", "Server", "" )
$showurl = IniRead("config.ini", "General", "Show", "" )

$iepath =  @ProgramFilesDir & "\Internet Explorer\iexplore.exe"

;~ Loop check for server and execute different commands for each state
While 1
    $servertest = Ping($server ,3000)
    $checkiemode = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings', 'GlobalUserOffline')
    ;~ If server ping responds OK and, in the Registry Internet state is set to offline...
    If $servertest <> 0 And $checkiemode = 1 Then
        $rw = RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "0" )
        If ProcessExists('iexplore.exe') Then ; See if IE is running before trying to close it.
            ProcessClose('iexplore.exe') ; This replaces Task Kill via cmd window
            ProcessWaitClose('iexplore.exe', 1000) ; Wait upto 1000 ms for process to close, If it closes quicker then 1000ms then script continues on 
        EndIf
        ShellExecute($showurl)
    ElseIf $servertest = 0 And $checkiemode = 0 Then
        RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "1" )    
        If ProcessExists('iexplore.exe') Then ; See if IE is running before trying to close it.
            ProcessClose('iexplore.exe') ; This replaces Task Kill via cmd window
            ProcessWaitClose('iexplorer.exe', 1000) ; Wait upto 1000 ms for process to close, If it closes quicker then 1000ms then script continues on 
        EndIf       
        ShellExecute($showurl)
    EndIf
    Sleep(5000)
WEnd

Maybe add a hotkey to exit the script as well

Add a pop up input box to a hotkey as well , so you can change the server address and url when felt like.

the list just goes on..lol

Good luck and

Cheers.

Edited by smashly

Share this post


Link to post
Share on other sites
JoaoCampos

ProcessExist() , ProcessClose , ProcessWaitClose .. these functions can do away with the Run Task Kill and extra Sleep() your adding.

;~ Get some var info from config file
$server = IniRead("config.ini", "General", "Server", "" )
$showurl = IniRead("config.ini", "General", "Show", "" )

$iepath =  @ProgramFilesDir & "\Internet Explorer\iexplore.exe"

;~ Loop check for server and execute different commands for each state
While 1
    $servertest = Ping($server ,3000)
    $checkiemode = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings', 'GlobalUserOffline')
    ;~ If server ping responds OK and, in the Registry Internet state is set to offline...
    If $servertest <> 0 And $checkiemode = 1 Then
        $rw = RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "0" )
        If ProcessExists('iexplore.exe') Then ; See if IE is running before trying to close it.
            ProcessClose('iexplore.exe') ; This replaces Task Kill via cmd window
            ProcessWaitClose('iexplore.exe', 1000) ; Wait upto 1000 ms for process to close, If it closes quicker then 1000ms then script continues on 
        EndIf
        ShellExecute($showurl)
    ElseIf $servertest = 0 And $checkiemode = 0 Then
        RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "GlobalUserOffline", "REG_DWORD", "1" )    
        If ProcessExists('iexplore.exe') Then ; See if IE is running before trying to close it.
            ProcessClose('iexplore.exe') ; This replaces Task Kill via cmd window
            ProcessWaitClose('iexplorer.exe', 1000) ; Wait upto 1000 ms for process to close, If it closes quicker then 1000ms then script continues on 
        EndIf       
        ShellExecute($showurl)
    EndIf
    Sleep(5000)
WEnd

Maybe add a hotkey to exit the script as well

Add a pop up input box to a hotkey as well , so you can change the server address and url when felt like.

the list just goes on..lol

Good luck and

Cheers.

Ive tested it before and the problem with processclose is that if i have more than one process called iexplore.exe, it only closes one of them.

Regards,

JC

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.