Sign in to follow this  
Followers 0
nevodj

Multiple whiles in script

3 posts in this topic

Hello... wondering if someone could help me with my script.

I have a sleep in the while so it only performs the function every 10 mins to save CPU usage etc.

I want to add a tray menu so user can configure email settings, startup options etc, obviously I can't use this while because it would only do TrayGetMsg every 10 mins.

If I add a while before it, it kills the second one...

What is the best way to do this?

Very basic script...! I do a lot of remote desktopping and static IP's arent always available...

#include <Inet.au3>
#cs
Opt("TrayMenuMode",11)
TrayCreateItem("")
$configitem   = TrayCreateItem("Configure")
TrayCreateItem("")
$exititem      = TrayCreateItem("Exit")

TraySetState()
While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $Configitem
            Msgbox(64,"Config","Config GUI here")
        Case $msg = $exititem
            Exit
    EndSelect
WEnd
#ce

$initialread = RegRead("HKEY_CURRENT_USER\Software\CheckIP", "CurrentWANIP")
If @error = 1 Then
MsgBox(64,"Initial Setup", "Creating Registry Entries...OK to continue")
RegWrite("HKEY_CURRENT_USER\Software\CheckIP", "CurrentWANIP", "REG_SZ","")
EndIf
While 1
Sleep(10000)
Global $PublicIP = _GetIP()
$iRead = RegRead("HKEY_CURRENT_USER\Software\CheckIP", "CurrentWANIP")
If $PublicIP <> -1 Then
If $PublicIP <> $iRead Then
UpdateIP()
EndIf
EndIf
WEnd
Func UpdateIP()
$s_SmtpServer = "smtp.server.com"
$s_FromName = "From Name"
$s_FromAddress = "[email="from@address.com"]from@address.com[/email]"
$s_ToAddress =  "[email="to@address.com"]to@address.com[/email]"
$s_Subject = "New IP Address"
Dim $as_Body[2]
$as_Body[0] = "Dynamic IP Address has changed. New IP Address is:"
$as_Body[1] = $PublicIP
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
RegWrite("HKEY_CURRENT_USER\Software\CheckIP", "CurrentWANIP", "REG_SZ",$PublicIP)
EndFunc

Share this post


Link to post
Share on other sites



Thanks! That should do the trick.

I just thought i may put the configuration module in a separate exe e.g. config.exe launched by TrayItemSetOnEvent on the checking service. Would keep it simpler and tidier.

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