Jump to content
Sign in to follow this  
romulous

Problem with winexists

Recommended Posts

romulous

Hi everyone,

I've been trying to write a script that runs in the background, and upon my firewall opening up a window titled: "Sygate Personal Firewall Pro {date} {time}" and the text (part of): "NT Kernel System has changed", the script would click the No button on that window. My script is below. It works fine...as long as the window is the active one (i.e. if the window pops up in the background and is not the active window, the script will not detect it until you click on the window to make it active). The problem is, only about 50% of the time will the firewall window be the active one. Anyway, I tried removing the 'winwaitactive' part of the script, but when I do, the script starts taking up 100% of my CPU and every time I try and open a new program window, the script pushes that window into the background (try killing the script process in Task Manager when it continually makes Task Manager a non active window!). Anyway, any help would be appreciated.

; Script Start - Add your code below here
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" ) Then; Polls windows to see if the window exists
    WinActivate ( "Sygate Personal Firewall Pro" ); Makes the Sygate window active
    WinWaitActive ( "Sygate Personal Firewall Pro" ); Makes sure the window is active
    $click1 = ControlClick ( "Sygate Personal Firewall Pro", "NT Kernel & System has changed since the last time you used it.This could happen if you have updated it recently. Click Detail to see more information. Do you want to allow it to access the network?", 2 ); Clicks the No button (and assigns output to variable)
    If $click1 = 1 Then MsgBox ( 0, "Note", "Sygate box has been clicked.", 5 ); If the Sygate box was clicked, then post MsgBox (testing only to see if script works, will remove later)
    EndIf
WEnd

(I had to put the full text of the firewall window in the $click1 line because though I worked out how to make AutoIt match part text on the window title, I could not work out how to make it do the same in the window text - in other words, if I only put part of the text in that line, the script would not work at all).

Edited by romulous

Share this post


Link to post
Share on other sites
MHz

Give this a try

Opt("TrayIconHide", 1)
Opt("WinTitleMatchMode", 2)
While 1
    If WinExists("Sygate Personal Firewall Pro", "NT Kernel & System has changed") Then
        ControlClick("Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2)
        WinWaitClose("Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2)
        MsgBox(0, "Note", "Sygate box has been clicked.", 5)
    EndIf
WEnd

:shocked:

Edit:

Having a Sleep in the loop will keep the cpu down also if the window does not exist, else the loop will go round too fast.

Edited by MHz

Share this post


Link to post
Share on other sites
romulous

Give this a try

Opt("TrayIconHide", 1)
Opt("WinTitleMatchMode", 2)
While 1
    If WinExists("Sygate Personal Firewall Pro", "NT Kernel & System has changed") Then
        ControlClick("Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2)
        WinWaitClose("Sygate Personal Firewall Pro", "NT Kernel & System has changed", 2)
        MsgBox(0, "Note", "Sygate box has been clicked.", 5)
    EndIf
WEnd

:shocked:

Edit:

Having a Sleep in the loop will keep the cpu down also if the window does not exist, else the loop will go round too fast.

Hi MHz,

Thanks for that. That code as is immediately starts using 100% CPU, but when I add in a sleep line as you suggested (I added 'sleep (2000)' on the line between EndIf and WEnd), that seems to do the trick. The CPU usage immediately drops to 0% and it doesn't seem to badly affect the running of the script. I guess the worst side effect would be if the window appeared immediately after a run of the script, it would be displayed on-screen for 2 seconds before the script detected it and closed it. That's not too bad though - I managed to test the script with the window as not being the active one, and the script does detect it now, which is what I was after.

Thanks again,

CM

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.