Jump to content

Help with improving a script


Recommended Posts

Hi everyone,

I was wondering if someone could help me improve the following script:

Opt ( "TrayIconHide", 1 ); Hides the AutoIt tray icon
Opt ( "WinTitleMatchMode", 2 ); Changes the AutoIt windows title matching mode to partial titles (Sygate window title has date and time in it which changes every time it is displayed)
While 1
    If WinExists ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed" ) Then; Polls windows to see if the window exists
        ControlClick ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2 ); Clicks the No button
        WinWaitClose ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2 ); Waits until the Sygate window has been closed
        MsgBox ( 0, "Note", "Sygate box has been clicked.", 2 ); If the Sygate box was clicked, then post MsgBox (testing only to see if script works, will remove later)
        Sleep ( 6000 ); Sleep for 6 seconds (time enough for MsgBox to disappear)
        ExitLoop; Exits the loop - I've noticed that the 'NT Kernel and System' dialog box only ever appears the once, so there is no point - once this script has acted on the Sygate dialog the first time - keeping it running. So, the script will run until the Sygate dialog appears, will close that dialog and then will close itself.
    EndIf
    Sleep ( 2000 ); Sleeps for 2 seconds before beginning loop again. If a Sleep line is not put into the script, CPU usage is taken to 100%. Side effect is that if Sygate window appears immediately after a run of the script, it will be 2 seconds before the script detects it.
WEnd

Exit; Exits

Basically, it works fine 999 times out of 1000. However, I have just a few minutes ago see it fail - basically the Sygate window popped up, I had another window open in the foreground, and then I heard the AutoIt script pop up the box to say that the Sygate window had been closed, but the Sygate window had not been closed. I'm still struggling to explain how this happened, how the script popped up the notification but hadn't actually clicked No on the Sygate dialog, but I'm pretty sure it has something to do with the Sygate window not being the active window at the time the script was triggered. Anyway, if anyone can help me improve it so it works 1000 out of 1000 times, that would be great (this is the first time it has failed in about 2 months of use, so I'm quite happy with it, it just needs some tuning by the looks of it.

Regards,

CM

Link to comment
Share on other sites

Hi everyone,

I was wondering if someone could help me improve the following script:

Opt ( "TrayIconHide", 1 ); Hides the AutoIt tray icon
Opt ( "WinTitleMatchMode", 2 ); Changes the AutoIt windows title matching mode to partial titles (Sygate window title has date and time in it which changes every time it is displayed)
While 1
    If WinExists ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed" ) Then; Polls windows to see if the window exists
        ControlClick ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2 ); Clicks the No button
        WinWaitClose ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2 ); Waits until the Sygate window has been closed
        MsgBox ( 0, "Note", "Sygate box has been clicked.", 2 ); If the Sygate box was clicked, then post MsgBox (testing only to see if script works, will remove later)
        Sleep ( 6000 ); Sleep for 6 seconds (time enough for MsgBox to disappear)
        ExitLoop; Exits the loop - I've noticed that the 'NT Kernel and System' dialog box only ever appears the once, so there is no point - once this script has acted on the Sygate dialog the first time - keeping it running. So, the script will run until the Sygate dialog appears, will close that dialog and then will close itself.
    EndIf
    Sleep ( 2000 ); Sleeps for 2 seconds before beginning loop again. If a Sleep line is not put into the script, CPU usage is taken to 100%. Side effect is that if Sygate window appears immediately after a run of the script, it will be 2 seconds before the script detects it.
WEnd

Exit; Exits

Basically, it works fine 999 times out of 1000. However, I have just a few minutes ago see it fail - basically the Sygate window popped up, I had another window open in the foreground, and then I heard the AutoIt script pop up the box to say that the Sygate window had been closed, but the Sygate window had not been closed. I'm still struggling to explain how this happened, how the script popped up the notification but hadn't actually clicked No on the Sygate dialog, but I'm pretty sure it has something to do with the Sygate window not being the active window at the time the script was triggered. Anyway, if anyone can help me improve it so it works 1000 out of 1000 times, that would be great (this is the first time it has failed in about 2 months of use, so I'm quite happy with it, it just needs some tuning by the looks of it.

Regards,

CM

From the help for ControlClick, which might explain your problem.

Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi,

Thanks - I've added a winactivate line as such. Will see how it goes!

If WinExists ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed" ) Then; Polls windows to see if the window exists
        WinActivate ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed" ); Make Sygate window the active window
        ControlClick ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2 ); Clicks the No button
Edited by romulous
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...