Jump to content

help for script loop


reber
 Share

Recommended Posts

hi. first, forgive my bad english :) im new at autoit scripting. i need some help. we had small network and we share same internet account. i try make a simple script. script ping ip and warn me (and i limit my active downloads). its running but only one time. how can create loop for scrip (e.g per a minute)? (script include some turkish words :) )

$var = Ping("192.168.1.4",500)
If $var Then
    
$ip = 1
Else
$ip = 0

EndIf

if $ip > 0 Then
        #Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)


        
        TraySetIcon(@WorkingDir & "\media\on.ico")
        Sleep(150)
        SoundPlay(@WorkingDir & "\media\alert.wav",1)
        Sleep(150)
        TrayTip("Uzak Kullanıcı Aktif", "uzak kullanıcı bilgisayarı kullanmakta", 10, 1)


$aboutitem      = TrayCreateItem("Hakkında...")
$exititem       = TrayCreateItem("Çıkış")


TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"Hakkında:","Gültekin GÖK copyleft 2009 for everyone")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
Else
    #Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)


        Sleep(150)
        TraySetIcon(@WorkingDir & "\media\off.ico")
        Sleep(150)
    


$aboutitem      = TrayCreateItem("Hakkında...")
$exititem       = TrayCreateItem("Çıkış")


TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"Hakkında:","Gültekin GÖK copyleft 2009 for everyone")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

    
EndIf
Link to comment
Share on other sites

Previous reply is bad.

Here is corrected version:

#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 1)

Global $start_time = TimerInit()

$aboutitem = TrayCreateItem("Hakkinda...")
$exititem = TrayCreateItem("Çikiş")
TraySetState()

While 1
 $msg = TrayGetMsg()
 Select
    Case $msg = 0
        ContinueLoop
    Case $msg = $aboutitem
        MsgBox(64, "Hakkinda:", "Gültekin GÖK copyleft 2009 for everyone")
    Case $msg = $exititem
        ExitLoop
 EndSelect
 
 If TimerDiff($start_time) > 1000 Then ; once a second
    $start_time = TimerInit()
    MyPing()
 EndIf
WEnd


Func MyPing()
 $var = ping("192.168.1.4", 500)
 If $var Then
    $ip = 1
 Else
    $ip = 0
 EndIf

 If $ip > 0 Then
    TraySetIcon(@WorkingDir & "\media\on.ico")
    Sleep(150)
    SoundPlay(@WorkingDir & "\media\alert.wav", 1)
    Sleep(150)
    TrayTip("Uzak Kullanici Aktif", "uzak kullanici bilgisayari kullanmakta", 10, 1)
 Else
    Sleep(150)
    TraySetIcon(@WorkingDir & "\media\off.ico")
    Sleep(150)
 EndIf
EndFunc   ;==>ping
Link to comment
Share on other sites

hi

the includes and other things with a "#" ar always up in the script

funcs ar always down in the script and the other things in the middle

thanks for your helps. im new at autoit but not far for scripting. i using multimedia builder and its syntax different from autoit. they re mixed up :)

thanks Zedna i ll try your script.

Link to comment
Share on other sites

Previous reply is bad.

Here is corrected version:

#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 1)

Global $start_time = TimerInit()

$aboutitem = TrayCreateItem("Hakkinda...")
$exititem = TrayCreateItem("Çikiş")
TraySetState()

While 1
 $msg = TrayGetMsg()
 Select
    Case $msg = 0
        ContinueLoop
    Case $msg = $aboutitem
        MsgBox(64, "Hakkinda:", "Gültekin GÖK copyleft 2009 for everyone")
    Case $msg = $exititem
        ExitLoop
 EndSelect
 
 If TimerDiff($start_time) > 1000 Then ; once a second
    $start_time = TimerInit()
    MyPing()
 EndIf
WEnd


Func MyPing()
 $var = ping("192.168.1.4", 500)
 If $var Then
    $ip = 1
 Else
    $ip = 0
 EndIf

 If $ip > 0 Then
    TraySetIcon(@WorkingDir & "\media\on.ico")
    Sleep(150)
    SoundPlay(@WorkingDir & "\media\alert.wav", 1)
    Sleep(150)
    TrayTip("Uzak Kullanici Aktif", "uzak kullanici bilgisayari kullanmakta", 10, 1)
 Else
    Sleep(150)
    TraySetIcon(@WorkingDir & "\media\off.ico")
    Sleep(150)
 EndIf
EndFunc   ;==>ping

hi. script looping continuously and tray menu not work :idea: how can i fix it? can i make differen funtions in script, and run selected one?

e.g:

function 1= check ip and show tray "on" icon, play alert sound and show tooltip ballon.

function 2= check ip, if remote pc not responsible show "off" icon at tray.

function 3= after some seconds (probably per a minute), check ip. if pc running do nothing, but pc inaccessible run fuction 2

please help :) otherwise my gabby neighbor melt my brain. :) in my perfect country, 1mbit internet connection fee only! 40 $. and super fast! you can only use it at 800kbps :P please help

Link to comment
Share on other sites

Now it works for me:

#include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 1)

Global $start_time = TimerInit()

$aboutitem = TrayCreateItem("Hakkinda...")
$exititem = TrayCreateItem("Çikiş")
TraySetState()

While 1
 $msg = TrayGetMsg()
 Select
   Case $msg = $aboutitem
       MsgBox(64, "Hakkinda:", "Gültekin GÖK copyleft 2009 for everyone")
   Case $msg = $exititem
       ExitLoop
 EndSelect
 
 If TimerDiff($start_time) > 1000 Then ; once a second
   MyPing()
   $start_time = TimerInit()
 EndIf
WEnd


Func MyPing()
 $var = ping("192.168.1.4", 500)
;~  $var = ping("www.google.com", 500)
 If $var > 0 Then
   TraySetIcon(@WorkingDir & "\media\on.ico")
   SoundPlay(@WorkingDir & "\media\alert.wav", 1)
   TrayTip("Uzak Kullanici Aktif", "uzak kullanici bilgisayari kullanmakta", 10, 1)
 Else
   TraySetIcon(@WorkingDir & "\media\off.ico")
 EndIf
EndFunc   ;==>ping
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...