[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Refresh System Tray / Automatically Close Application

Posted on 2004-11-25
17
Medium Priority
?
3,225 Views
Last Modified: 2009-12-03
hi,
i have a batch file which runs some automated tasks, and as part of these, it runs an application, then uses pskill (process kill) to close the application. this is because there is no automated way of closing it. it runs in the system tray and to manually close it i would have to right click on it and click exit. however cause of this way of closing it, the icon is left in the system tray of the application and when i move the mouse over it, it disappears just as u would imagine.

however i want a program or some way of refreshing the system tray icons, so these "dead" icons dont hang about.

alternatively, a way to close the application in the system tray automatically from a batch file would be useful!

i'm using Windows 2000 Server SP4.

i know about making any application a service and i dont wanna do that with this one.

any suggestions appreciated.

thanks
0
Comment
Question by:ianmarchant
  • 7
  • 7
  • 3
17 Comments
 
LVL 10

Expert Comment

by:kcarrim
ID: 12673918
You will need to find window handle of the system tray, gets its bounding rectangle, and programmatically moves the mouse over it.
I believe the operative API is GetWindowRect, documented at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/GetWindowRect.asp 

Getting the system tray's handle seems to consist of (assuming the user hasn't switched shells):

ControlHandle=cWndByWndSpec("Shell_TrayWnd","explorer",0)

So the code would look something like this:
ControlHandle=cWndByWndSpec("Shell_TrayWnd","explorer",0)
buf = BinaryAlloc(16)
dll = StrCat(DirWindows(1), "USER32.DLL")
DllCall(dll, long:"GetWindowRect", long:ControlHandle, lpbinary:buf)
BinaryEodSet(buf, 16)
left = BinaryPeek4(buf, 0)
top = BinaryPeek4(buf, 4)
right = BinaryPeek4(buf, 8)
bottom = BinaryPeek4(buf, 12)
BinaryFree(buf)
Message("Coordinates", "%left% %top% %right% %bottom%")

Now use the MousePlay function to move the mouse to those coordinates

Or you can use tray utility
>>http://www.4t-niagara.com/4t-min.zip>>Free Ware
>>http://www.pssoftlab.com/download/pstrayf.zip>>Share Ware
0
 

Author Comment

by:ianmarchant
ID: 12674081
thanks for the quick response!

sorry, but i hardly know anything about programming, so have no idea what to do with all that.... can u write me a script to do this?

those tray utilties are for minimising applications to the system tray, i thought? how could they help in this situation?
0
 

Author Comment

by:ianmarchant
ID: 12674770
also forgot to mention, that for security reasons this pc is always locked, so i need this to happen while it is locked... i realise this may make things more difficult, but applications and tasks still work even while a pc is locked, so i'm sure this is possible. if not, a workaround would be to refresh the system tray when i unlock the pc.

thanks for the help ;)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:jatcan
ID: 12678839
You could also try killing explorer.exe and re-starting it...not sure how this woudl affect running services but I think not at all...

If you kill you program, then kill explorer, then restart explorer does the icon stay there or do just those that were running return...? I think the icons would not return although I haven't had the opportunity to actually try it, why don't you let me know...?

J
0
 
LVL 7

Expert Comment

by:jatcan
ID: 12678993
Ok-one more thing, not sure if it will work or not, never tried it, but if you're willing we could always go to this key in the registry:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify

and delete these two dwords from the right hand side:

IconStreams
PastIconsStream

that should take care of any icon history, I am not sure if the key's will be re-created or not upon starting the program and then killing it once more,
without them, the systray should keep any history at all but simply destroy the icon once the process has been killed..Not sure if this will have any effect or not as the problem seems to be the wait time between killing the app and the system tray being notified of it...but we'll see.

John
0
 
LVL 10

Expert Comment

by:kcarrim
ID: 12679071
You don't need to be much of a programmer. See here : http://www.winbatch.com
Use the info in my previous post together with Winbatch
0
 
LVL 10

Accepted Solution

by:
kcarrim earned 2000 total points
ID: 12679079
This adjustment will ensure that any inactive icons are automatically hidden from view when they’re not active. You’ll need to go along to HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer and create or edit the DWORD value EnableAutoTray. To hide inactive icons set a value of 1 and to display them again, enter 2
0
 
LVL 7

Expert Comment

by:jatcan
ID: 12679446
Winbatch looks like a great programming--I got tired of payingfor software--Linux is really great that way...

AND, kcarrim, I supposed that would refresh the system tray while it hid and un-hid? That would definately be a work around for me if it works!

Cheers,

Jatcan
0
 

Author Comment

by:ianmarchant
ID: 12715228
i dont want to use the kill explorer etc option, this is far too messy and could lead to system instability. plus i would loose the systemtray icons of the other applications i have running.

i think by deleting those keys, it would probably loose the icons of the other applications i have running aswell.

although winbatch looks useful, it looks far too complicated for doing what i need to do. and possible wouldnt b able to refresh the icons while the pc is locked anyway.

i'll try the "enableautotray" reg fix later, and let u know how i get on. is this similar to the built in option in XP where it hides the icons?

thanks for the suggestions guys.
0
 

Author Comment

by:ianmarchant
ID: 12721872
kcarrim: by inactive icons, what does that mean? cause i have a few other applications which minimize to the systemtray, and obviously dont want them to disappear... what does it class as "inactive" or does it mean the way XP does it, when a icon hasnt actually made some on screen activity or hasnt been clicked on by the user?
0
 
LVL 10

Expert Comment

by:kcarrim
ID: 12724434
On windows xp, the taskbar can be customized to hide or show inactive icons. This basically means that if the program has not ben accessed for a certain amount of time, the icon will be hidden. You can customize notifications. Say for exaple you are running spybot, the icon only gets hidden once it has been idle. If you look closely; right click taskbar, properties, check the box reading Hide inactive icons. Next to it is a button Customize. Look for Spybot, click on Spybot. You now have three options. Always show, Always hide and Hide when inactive. You will see current and past items. You can set the properties of you batch file's icon here. Have it always hidden!!
0
 

Author Comment

by:ianmarchant
ID: 12724633
ok, thats probably what I want then!

will making that registry change enable that on Windows 2000 though???

0
 
LVL 10

Expert Comment

by:kcarrim
ID: 12725275
Yes.
0
 

Author Comment

by:ianmarchant
ID: 12781803
sorry for the delay, i've made the change... will i need to reboot for it to take effect?
0
 
LVL 10

Expert Comment

by:kcarrim
ID: 12782480
Any changes to the registry requires a reboot.
0
 

Author Comment

by:ianmarchant
ID: 12997739
thanks for the help/suggestions everyone.
0
 
LVL 10

Expert Comment

by:kcarrim
ID: 13003313
Cool!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question