Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 05, 2016, 02:46:03 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Advice needed on AHK script  (Read 8579 times)

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #25 on: May 13, 2013, 05:40:58 AM »
I'll let you know the results.

Something I noticed yesterday which has probably been going on all the time is that my Windows 7 PC and my Netbook (XP) both have programs that produce pop-ups when you hold the cursor over the tray icons, on 7 it is USB Safely Remove, on XP it is Battery Monitor, when I run any of the tray cleaning programs the pop-ups appear.

I am attaching the tray cleaning program I put together from the AHK script for you to try if you want to, this morning I tried variations of it by reducing the number of times the script repeats, (the default is 4) I found that 3 repeats is also removing all the icons but any less and some get left behind. I have left it at 4 to give it a bit of leeway.

I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #26 on: May 13, 2013, 07:46:10 AM »
After fairly extensive testing I have found that the pop-ups I mentioned are no longer appearing with CleanTray, and with 4 programs running, Network Activity Indicator being the fourth, these are the results:

no switch: leaves 1 or more icons
/once: only removed 1 icon
/debug /once: worked perfectly
/m: worked perfectly

However, if I am running a PPTP VPN (i.e. using PPTPchek) the last 2 switches both leave 1 icon behind, not necessarily the same one each time.
Running the OpenVPN Adapter seemed to make no difference but then it doesn't have its own icon.
As far as I could tell none of the above rearranged any icons.

Although I know it's not you usual program of choice I am wondering if it is possible to prevent the pop-ups appearing when using the AHK script?
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi
« Last Edit: May 13, 2013, 07:56:05 AM by pilgrim »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #27 on: May 15, 2013, 09:51:06 PM »
    Something I noticed yesterday which has probably been going on all the time is that my Windows 7 PC and my Netbook (XP) both have programs that produce pop-ups when you hold the cursor over the tray icons, on 7 it is USB Safely Remove, on XP it is Battery Monitor, when I run any of the tray cleaning programs the pop-ups appear.

    Although I know it's not you usual program of choice I am wondering if it is possible to prevent the pop-ups appearing when using the AHK script?

    OK, at this point you should de-fiddle your system because those things don't appear unless the mouse has been over the target icon for at least 400ms by default, so this implies you've dropped the delay to almost, (if not), 0.

    I've set mine to 30ms and they don't appear, CleanTray moves the mouse at the fastest speed AutoIt can which takes less than 10ms to traverse an area the width of your SysTray three times.  With the /debug switch it takes ~1.5 seconds to do it.

    Add to the fact that to remove 4 icons it will do a total of 5 cycles, that's 15 runs in total over that area in less than a second.

    Your icons are about 24x24 pixels by the looks, (tray height of 28), a total of about 26 icons: 630 pixels in ~3ms / 26 = ~0.11ms per icon.

    Even with the /debug switch it's ~20ms per icon.

    I set my taskbar the same, (as close as possible), a single row at the bottom with about 28 notification icons, and 4-6 orphaned at the left - in every case CleanTray worked no matter where the taskbar was located, (top, bottom, left, right), or whether it's hidden or not, (provided the icon had no background process).

    Quote
    I am attaching the tray cleaning program .....

    Doesn't do a thing here, exits immediately.

    Addendum: Since you said Terminator worked for both D4 and NAI I've been playing with it a bit more and you can try this version out.

    Terminator: Terminate a program that has a SysTray icon

    Terminate.exe [/mess] [/context [/test]] [/kill] [/blitz] [/list] <process>
    Where: /mess    - sends a WM_CLOSE message to programs window
               /context - opens the programs SysTray context menu and chooses
                              the last entry (usually Exit/Quit)
               /kill       - kill the process and then remove the SysTray
                              icon
               /blitz     - tries everything
               /list       - list processes with SysTray icons
               /test      - opens the icon context menu and selects the
                              last item but doesn't activate it
                              (only valid with /context switch)

    The switches can be abbreviated to the first character, ie. /l, /t, /m, /c, /k

    If you put multiple methods on the command line it'll only do one in this order: message, context menu and finally kill.

    eg. Terminator.exe /kill /context peerblock.exe will use the context menu to try and close peerblock.exe

    NOTES:
    • Only works with programs that have a SysTray icon
    • Only works with programs that don't open a modal requester, (currently), ie. "Are you sure?"
    • Not sure if it will work for the hidden icon area in Vista+

    So in your case you could try:

    terminator.exe /m d4.exe
    terminator.exe /m networkindicator.exe
    terminator.exe /c peerblock.exe
    terminator.exe /c sbiectrl.exe

    It doesn't do anything that's OS unfriendly, (/k does the same thing as taskkill), tested it here on Win7 on various tray dwelling programs, (but only for D4, NAI and PeerBlock in your specific case), and it seemed to work OK - system didn't crash, all my drives still seem to be full of junk.

    I'm sure one of the other programmers here could come up with something a lot nicer  :D

    UPDATE:
    • Tries sending WM_CLOSE 5 times at 5ms intervals, (the Pilgrim factor)
    • Added /blitz option

    Source added to archive 20130523
    « Last Edit: May 23, 2013, 01:45:50 AM by 4wd »

    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #28 on: May 16, 2013, 04:51:54 AM »
    OK, at this point you should de-fiddle your system because those things don't appear unless the mouse has been over the target icon for at least 400ms by default, so this implies you've dropped the delay to almost, (if not), 0.

    I just tried manually moving the cursor over the USB SR icon and a 400ms delay seems about right.
    Looking at the basic script I started from the only figure that I can see that could relate to a delay is the 200?
       
    Quote
    WM_MOUSEMOVE := 0x200

       ControlGetPos, xTray,, wTray,, ToolbarWindow321, ahk_class Shell_TrayWnd
       endX := xTray + wTray
       x := 5
       y := 12

       Loop
       {
          if (x > endX)
             break
          point := (y << 16) + x
          PostMessage, %WM_MOUSEMOVE%, 0, %point%, ToolbarWindow321, ahk_class Shell_TrayWnd
          x += 18
       }

    Quote
    Quote
    I am attaching the tray cleaning program .....

    Doesn't do a thing here, exits immediately.

    Now that does surprise me because I have it working on both 7 and XP.
    The complete script reads as follows:

    Quote
    rem Check if our flag file exists and act accordingly
    if exist internet_is_on.txt goto running

    rem Turning Internet items ON
    echo hah>internet_is_on.txt

    start /D "C:\Program Files (x86)\D4" D4.exe
    start /D "C:\Program Files (x86)\Sandboxie" SbieCtrl.exe
    start /D "C:\Program Files (x86)\PeerBlock" peerblock.exe
    start /D "C:\Program Files (x86)\network-activity-indicator" NetworkIndicator.exe

    netsh interface set interface "Router Connection" ENABLED

    goto alldone

    :running
    rem Internet is ON, turn it all OFF now
    del internet_is_on.txt

    taskkill /F /IM peerblock.exe
    taskkill /F /IM SbieCtrl.exe
    taskkill /F /IM D4.exe

    netsh interface set interface "Router Connection" DISABLED

    netsh interface set interface "OpenVPN Adapter" DISABLED

    rasdial /disconnect

    Taskkill /F /IM NetworkIndicator.exe

    start /d "C:\Program Files (x86)\Refresh Tray" RefreshTray.exe

    :alldone

    I'll give the new version of Terminator a run and let you know.
    Just out of curiosity where do you put the exe, in the same folder as the batch file, System32?

    Quote
    I'm sure one of the other programmers here could come up with something a lot nicer  :D

    Nice is good, efficient is better. :)
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #29 on: May 16, 2013, 05:44:34 AM »
    OK, at this point you should de-fiddle your system because those things don't appear unless the mouse has been over the target icon for at least 400ms by default, so this implies you've dropped the delay to almost, (if not), 0.

    I just tried manually moving the cursor over the USB SR icon and a 400ms delay seems about right.

    Well, in that case I'm stumped as to why you'd be getting the tooltips appearing so quick, I've got Zentimo running and it's menu doesn't appear unless the mouse is stationary over the icon, (or moving very slowly - far slower than CleanTray moves it).

    At this point because I can't replicate exactly what you're seeing on any of my machines, (XP x86, Win7 x64, Win8 x86, WHS2011 x64), I'll have to say there's not much more I can do with CleanTray unless someone else can provide a bit more insight.

    Quote
    Looking at the basic script I started from the only figure that I can see that could relate to a delay is the 200?

    That's a question for our AHK specialists  ;)

    Quote
    I'll give the new version of Terminator a run and let you know.

    Assuming it might work:

    Code: Text [Select]
    1. netsh interface show interface "Router Connection" | find /i "disabled" >NUL
    2. if errorlevel 1 goto running
    3.  
    4. rem Turning Internet items ON
    5. start /D "C:\Program Files (x86)\D4" D4.exe
    6. start /D "C:\Program Files (x86)\Sandboxie" SbieCtrl.exe
    7. start /D "C:\Program Files (x86)\PeerBlock" peerblock.exe
    8. start /D "C:\Program Files (x86)\network-activity-indicator" NetworkIndicator.exe
    9.  
    10. netsh interface set interface "Router Connection" ENABLED
    11.  
    12. goto alldone
    13.  
    14. :running
    15. rem Internet is ON, turn it all OFF now
    16. terminator.exe /c peerblock.exe
    17. terminator.exe /c SbieCtrl.exe
    18. terminator.exe /m D4.exe
    19.  
    20. netsh interface set interface "Router Connection" DISABLED
    21.  
    22. netsh interface set interface "OpenVPN Adapter" DISABLED
    23.  
    24. rasdial /disconnect
    25.  
    26. terminator.exe /m NetworkIndicator.exe
    27.  
    28. :alldone

    Quote
    Just out of curiosity where do you put the exe, in the same folder as the batch file, System32?

    Anywhere in a path or call it with the full path to it, if it was me I'd try to keep all "foreign" files out of System32 and just put it in the same directory as the batch files, (which you might need to add to the system path).

    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #30 on: May 17, 2013, 06:07:36 AM »
    I tried the latest version of Terminator using the script you posted above and putting the EXE in the same folder.
    Once again I'm afraid the results were inconsistent, the very first time it shut down everything, after that it left anything from 1 to 3 programs running.
    I made the alterations before I did anything else so the first time it was run was the first time it was connected to the internet after being turned on today.

    NAI closed nearly every time, D4 closed the majority of times, either one or both of the other two were always left running.

    The only remaining possibility I can think of is a clash with something else I have running.

    I have taken the first part of your script and modified my batch file so it no longer creates a flag file.
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #31 on: May 17, 2013, 06:36:18 AM »
    Try terminator.exe /k instead.

    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #32 on: May 17, 2013, 10:29:25 AM »
    Try terminator.exe /k instead.

    12 attempts, worked every time. :Thmbsup: :D

    Question 1) Is it possible to hide the cursor from showing over the icons?
    Question 2) Is it possible to create Terminator2 that leaves out NAI (not needed on XP)?
    Question 3) When you've answered question 1 any chance of a copy of the code so that I can see if I can translate it into AHK?
    Question 4) I can edit the 2 AHK programs I put together with Resource Hacker, that doesn't work with Terminator (with the exception of the icons), would that be true of all AutoIt programs?
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #33 on: May 17, 2013, 11:58:12 AM »
    Try terminator.exe /k instead.

    12 attempts, worked every time. :Thmbsup: :D

    There must be some strange timing issues on your computer, (which don't seem to appear on any of mine), for /m not to work with D4 and NAI occasionally.

    Quote
    Question 1) Is it possible to hide the cursor from showing over the icons?

    The cursor is moved over the icon so Windows can remove it, then it gets put back in it's original position, (at least I think I put that part in = I'll check when I wake up).

    EDIT: Yep, it's in there - the mouse moves back to wherever it started before the program was invoked.

    Are you saying that the mouse stays over the tray icon position after it's already killed the program?

    If so, this might be the cause of the inconsistent results with CleanTray/Terminator - something eating mouse movements or the system being abnormally slow to respond, (although I can't think of much that's slower than my Win8Pro Atom N270 netbook with a 4200RPM HDD  :-\ ).

    Quote
    Question 2) Is it possible to create Terminator2 that leaves out NAI (not needed on XP)?

    Um, can't you just not have that line in your batch file?

    Quote
    Question 3) When you've answered question 1 any chance of a copy of the code so that I can see if I can translate it into AHK?

    Can't wait to see that :D  When I've cleaned up the code a bit.

    Quote
    Question 4) I can edit the 2 AHK programs I put together with Resource Hacker, that doesn't work with Terminator (with the exception of the icons), would that be true of all AutoIt programs?

    I have no idea, Terminator was compiled as a CLI program, wasn't designed to be run from the Windows interface.

    There's an update to CleanTray and Terminator so try:

    CleanTray.exe /pilgrim

    and

    Terminator.exe /m d4.exe
    Terminator.exe /m networkindicator.exe

    or

    Terminator.exe /b <process>
    « Last Edit: May 17, 2013, 11:13:48 PM by 4wd »

    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #34 on: May 18, 2013, 03:56:31 AM »
    There must be some strange timing issues on your computer, (which don't seem to appear on any of mine), for /m not to work with D4 and NAI occasionally.

    I actually tried setting them all to /m before I tried /k but only the /k worked properly.

    Quote
    Are you saying that the mouse stays over the tray icon position after it's already killed the program?

    No, it was purely cosmetic so that you do not actually see the icon moving.

    Quote
    or the system being abnormally slow to respond

    I did wonder if this was an issue on the NC10 because even running Refresh Tray it takes a time to clear everything.

    Quote
    Um, can't you just not have that line in your batch file?

    Sorry, I was thinking that was set in the program not the batch file. (Ignore.)

    Quote
    Can't wait to see that :D  When I've cleaned up the code a bit.

    Thanks, don't hold your breath.

    Quote
    I have no idea, Terminator was compiled as a CLI program, wasn't designed to be run from the Windows interface.

    (Sound of penny dropping.) Thanks.

    I'll get back to you on the updates.
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #35 on: May 18, 2013, 07:11:33 AM »
    There must be some strange timing issues on your computer, (which don't seem to appear on any of mine), for /m not to work with D4 and NAI occasionally.

    I actually tried setting them all to /m before I tried /k but only the /k worked properly.

    /m won't work on PeerBlock/SandBoxie because they won't allow other programs to close them, (security measure I presume), therefore it's context menu or just kill them.

    Quote
    No, it was purely cosmetic so that you do not actually see the icon moving.

    Yes...well, given your systems fussiness towards things that are too fast....it's set at the second fastest setting.  At the fastest, the mouse gets teleported to the position - exactly what CleanTray does but your system didn't like that.

    Oh, forgot, can you try Terminator.exe /c on PeerBlock/SandBoxie again - added a couple of small, (5ms or so), delays into the mix.

    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #36 on: May 18, 2013, 09:54:25 AM »
    Quote
    No, it was purely cosmetic so that you do not actually see the icon moving.

    That was meant to be the cursor, not the icon. I was wondering if the cursor could be hidden when it was moving?

    CleanTray: Appears to be working without problems.

    Terminator: Went back to your script above (Reply 29) and it shut everything down except Peerblock. I just changed that to /b and left the rest as it was, it worked. As it was working I never tried any of the other combinations of switches.

    Each of the above was tried at least a dozen times.

    I tried adding a PPTP VPN to both of the above and got some interesting results.
    I tried it with CleanTray and PPTPchek shut down every time. I then tried it with Terminator and it hung, went back to CleanTray and it was hanging with that as well.
    From then on it was hanging more often than not with both programs.
    I know we have a separate thread for PPTPchek but I thought it worth mentioning here as it relates to testing the other two programs.
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #37 on: May 18, 2013, 08:42:44 PM »
    I tried it with CleanTray and PPTPchek shut down every time. I then tried it with Terminator and it hung, went back to CleanTray and it was hanging with that as well.

    OK, now that's just strange, I'll go back to seeing if I can find another way to check for PPTP/L2TP connections.

    In the meantime, your batch file could do with a little rearrangement, (didn't really take notice before  :-[ ).  By rights you should be closing down in the opposite order to the setting up, so:

    Code: Text [Select]
    1. netsh interface show interface "Router Connection" | find /i "disabled" >NUL
    2. if errorlevel 1 goto running
    3.  
    4. rem Turning Internet items ON
    5. start /D "C:\Program Files (x86)\D4" D4.exe
    6. start /D "C:\Program Files (x86)\network-activity-indicator" NetworkIndicator.exe
    7. start /D "C:\Program Files (x86)\Sandboxie" SbieCtrl.exe
    8. start /D "C:\Program Files (x86)\PeerBlock" peerblock.exe
    9.  
    10. netsh interface set interface "Router Connection" ENABLED
    11.  
    12. goto alldone
    13.  
    14. :running
    15. rem Internet is ON, turn it all OFF now
    16.  
    17. rasdial /disconnect
    18. netsh interface set interface "OpenVPN Adapter" DISABLED
    19. netsh interface set interface "Router Connection" DISABLED
    20.  
    21. terminator.exe /b peerblock.exe
    22. terminator.exe /c SbieCtrl.exe
    23. terminator.exe /m NetworkIndicator.exe
    24. terminator.exe /m D4.exe
    25.  
    26. :alldone

    Also, if Terminator works there shouldn't be a need for CleanTray to be run, soooo, having the VPN disconnection first might be enough of a delay such that by the time Terminator runs, PPTPchek has already exited because the VPN no longer exists.

    Anyways, back the PPTPchek drawing board...


    pilgrim

    • Supporting Member
    • Joined in 2008
    • **
    • Posts: 316
    • Cogito ergo ?
      • View Profile
      • Pilgrim's Page
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #38 on: May 19, 2013, 10:38:24 AM »
    There is actually a madness to my method. (Or should that be the other way round?)  :)

    The start commands are in the order the icons are arranged in the tray, right to left from the top.
    The terminate commands are in reverse order except for NAI, the reason for that is because in the short time it takes for everything to shut down it gives the NAI icon time to indicate that the main connection has been disabled, it greys out.
    I agree that the disconnect/disable commands needed rearranging as the main connection should have been last.

    I have now rearranged it to the following:

    Quote
    netsh interface show interface "Router Connection" | find /i "disabled" >NUL
    if errorlevel 1 goto running

    rem Turning Internet items ON
    start /D "C:\Program Files (x86)\D4" D4.exe
    start /D "C:\Program Files (x86)\Sandboxie" SbieCtrl.exe
    start /D "C:\Program Files (x86)\PeerBlock" peerblock.exe
    start /D "C:\Program Files (x86)\network-activity-indicator" NetworkIndicator.exe

    netsh interface set interface "Router Connection" ENABLED

    goto alldone

    :running
    rem Internet is ON, turn it all OFF now

    rasdial /disconnect
    netsh interface set interface "OpenVPN Adapter" DISABLED
    netsh interface set interface "Router Connection" DISABLED

    terminator.exe /b peerblock.exe
    terminator.exe /c SbieCtrl.exe
    terminator.exe /m D4.exe
    terminator.exe /m NetworkIndicator.exe

    :alldone

    Until now I have still been using taskkill and RefreshTray as I have tried so many variations of programs I wanted to be able to fall back each night on one that I knew was working.

    I tried various modifications on the existing RefreshTray script to stop the pop-up from opening but nothing worked, so if there is an answer in AHK it looks like it needs an extra command.
    I found that USB SR has an option to disable mouse-over for its pop-up but that means it needs to be activated manually and once it opens it stays there until I close it manually, no point.
    I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
    I've not had to try since.

    I wonder what happens if I click on thi

    4wd

    • Supporting Member
    • Joined in 2006
    • **
    • Posts: 4,474
      • View Profile
      • Donate to Member
    Re: Advice needed on AHK script
    « Reply #39 on: May 23, 2013, 01:47:45 AM »
    Source added to Terminator archive, maybe someone can make it a lot better, (and neater please).