Main Area and Open Discussion > General Software Discussion
Advice needed on AHK script
pilgrim:
I've given up - your system is just plain weird. :D
--- End quote ---
I know the OS thinks it's got a mind of its own. :)
In theory, no left over icons because the programs are cleanly shut down.
I've only tested with those 3 programs so who knows what else can happen.
--- End quote ---
With a name like that it sounds like the software equivalent of Arnie. :huh:
BTW, why do you run a separate time service?
You could just run w32tm /resync if you want to synchronise your system clock - one less program to kill badly :)
--- End quote ---
Partly through habit, I've been using it nearly as long as I've had a computer, partly because I didn't want to use the built in service, partly because it's very easy to set up both in terms of using my own server list and how often it runs, partly because it uses very few resources and it puts an icon in the system tray which shows the last time it synchronised, having it set to run every 15 minutes gives a good indication of firewall/connection problems for very little cost in terms of resources.
Having just looked up your suggestion I'll stick with D4.
pilgrim:
"Arnie" never moved anything. :(
If you decide to try again the fourth program in 7 is 'NetworkIndicator.exe' (not needed in XP) but I think my system tray is as determined as you are. :)
I asked you before about how the various scripts were different, does the AHK script in reply 1 translate into AutoIt or is that what you have been trying?
Because so far that is still the only thing that has worked without side effects.
4wd:
"Arnie" never moved anything. :(-pilgrim (May 09, 2013, 10:40 AM)
--- End quote ---
It doesn't "move" anything, all it does is send a WM_CLOSE message to the process, (which worked 100% of the time for D4 here), and if that failed it went to the tray icon, opened it's menu and chose the last item, (normally Exit/Quit - that had a ~95% success rate on the other two programs). ie. You use it to end the processes instead of taskkill.
I asked you before about how the various scripts were different, does the AHK script in reply 1 translate into AutoIt or is that what you have been trying?
--- End quote ---
Tested on XP x86, Win7 x64 and Win8 x86, (medium, high and low spec hardware respectively).
CLI use only.
CleanTray: Clears orphaned icons from Notification Area
CleanTray.exe [/debug] [/once] [/timer] [/mensa] [/nuke]
Where: /debug - outputs debug information to the console
/once - only runs over the Notification Area once (only valid for default method)
/timer - displays time taken at the end
/mensa - only moves mouse to orphaned icons
/nuke - blitzes the tray using system calls (icon positions will be lost)
/pilgrim - adds a 1ms delay between mouse movements
Default method is to traverse the tray using the mouse.
The default method is the slowest if there is more than one icon to remove and /mensa has priority over /nuke if you happen to enter both on the command line.
--- Code: AutoIt ---#NoTrayIcon#region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_UseUpx=n#AutoIt3Wrapper_Change2CUI=y#AutoIt3Wrapper_Res_Fileversion=0.2.0.20#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y#endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3>#include <_SysTray.au3>#include <_OsVersionInfo.au3> Global $debug = False, $once = False, $timer = False, $method = 0, $pilgrim = False If $CmdLine[0] > 0 Then For $i = 1 To $CmdLine[0] Switch StringLower(StringStripWS($CmdLine[$i], 8)) Case "/debug", "/d" $debug = True Case "/once", "/o" $once = True Case "/timer", "/t" $timer = True Case "/mensa", "/m" $method = 1 Case "/nuke", "/n" If $method <> 1 Then $method = 2 Case "/pilgrim", "/p" $pilgrim = True Case Else _DisplayUsage() Exit EndSwitch NextEndIf Global $posTray = WinGetPos(_FindTrayToolbarWindow()) ; find the trayIf $method <> 2 Then $oldPos = MouseGetPos() ; save mouse position MouseMove($posTray[0], $posTray[1], 0) ; move mouse to tray WinWait("[CLASS:Shell_TrayWnd]", "", 5) ; wait for the tray to open if hiddenEndIf If $debug Then ConsoleWrite("Desktop Width: " & @DesktopWidth & @CRLF & "Desktop Height: " & @DesktopHeight & @CRLF) ConsoleWrite("Notification area dimensions: " & _ArrayToString($posTray, ",") & @CRLF) $delay = 1Else $delay = 0EndIf If $timer Then $start = TimerInit()Switch $method Case 0 $count = 1 $ret = 0 $j = 0 While $count <> $ret $j += 1 $count = _SysTrayIconCount() $ret = _SeeYouNextYear() If $once Then ExitLoop WEnd Case 1 _TharHeIsGetIm() Case 2 _NukeEmAll() Case ElseEndSwitchIf $timer Then ConsoleWrite("Time: " & Round(TimerDiff($start) / 1000, 2) & " seconds")If $method <> 2 Then MouseMove($oldPos[0], $oldPos[1], 0) ; move mouse back where it came fromExit Func _DisplayUsage() Local $data = "CleanTray: Clears orphaned icons from Notification Area" & @CRLF & @CRLF & _ "CleanTray.exe [/debug] [/once] [/timer] [/mensa] [/nuke]" & @CRLF & _ "Where: /debug - outputs debug information to the console" & @CRLF & _ " /once - only runs over the Notification Area once" & @CRLF & _ " (only valid for default method)" & @CRLF & _ " /timer - displays time taken at the end" & @CRLF & _ " /mensa - only moves mouse to orphaned icons" & @CRLF & _ " /nuke - blitzes the tray using system calls" & @CRLF & _ " (icon positions will be lost)" & @CRLF & _ "Default method is to traverse the tray using the mouse." & @CRLF ConsoleWrite($data)EndFunc ;==>_DisplayUsage Func _SeeYouNextYear() If $posTray[0] >= @DesktopWidth Then $posTray[0] = @DesktopWidth - $posTray[2] If $posTray[1] >= @DesktopHeight Then $posTray[1] = @DesktopHeight - $posTray[3] If $posTray[0] < 0 Then $posTray[0] = 0 If $posTray[1] < 0 Then $posTray[1] = 0 Local $y = $posTray[1] While $y < $posTray[3] + $posTray[1] Local $x = $posTray[0] While $x < $posTray[2] + $posTray[0] MouseMove($x, $y, $delay) If $pilgrim Then Sleep(1) If $debug Then ConsoleWrite($x & ',' & $y & @CRLF) $x += 12 WEnd $y += 12 WEnd Return _SysTrayIconCount()EndFunc ;==>_SeeYouNextYear Func _TharHeIsGetIm() $flag = False Local $count = _SysTrayIconCount() ; get number of icons in tray For $i = $count - 1 To 0 Step -1 ; step backwards through the list Local $handle = _SysTrayIconHandle($i) ; get handle of the icon Local $pid = WinGetProcess($handle) ; get process ID for ithe handle If $pid = -1 Then ; if no process then Local $iPos = _SysTrayIconPos($i) ; get icon position MouseMove($iPos[0], $iPos[1], $delay) ; move mouse there If $debug Then ConsoleWrite($iPos[0] & ',' & $iPos[1] & @CRLF) If _SysTrayIconCount() < $count Then ; if number of icons has reduced, set flag and exit for/next loop $flag = True ExitLoop EndIf EndIf Next If $flag Then _TharHeIsGetIm() ; if flag set call func again (a little pseudo-recursion) MouseMove($oldPos[0], $oldPos[1], 0) ; move mouse back where it came fromEndFunc ;==>_TharHeIsGetIm Func _NukeEmAll() $count = _SysTrayIconCount() For $i = $count - 1 To 0 Step -1 $handle = _SysTrayIconHandle($i) $pid = WinGetProcess($handle) If $pid = -1 Then _SysTrayIconRemove($i) Next If _OsVersionTest($VER_GREATER_EQUAL, 6, 1) Then $countwin7 = _SysTrayIconCount(2) For $i = $countwin7 - 1 To 0 Step -1 $handle = _SysTrayIconHandle($i, 2) $pid = WinGetProcess($handle) If $pid = -1 Then _SysTrayIconRemove($i, 2) Next EndIfEndFunc ;==>_NukeEmAll
pilgrim:
I'll have to come back to this but two quick points:
1) D4 doesn't have an Exit/Quit option in the icon menu.
2) When I originally put this batch file together using 'taskkill' on its own only shut down D4, I had to add the /F switch to shut down the other two.
pilgrim:
Having finally caught up with myself:
Terminator.exe - It shut down D4 and removed the icon, the Network Activity Indicator Icon also disappeared. The other two programs stayed put.
What I did get was a lot of context menus left open including one for the next icon in line that is running all the time and one for the taskbar itself?
CleanTray.exe - Only removes the icon furthest to the left.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version