Refresh System Tray / Automatically Close Application

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
ianmarchantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kcarrimCommented:
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
ianmarchantAuthor Commented:
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
ianmarchantAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

jatcanCommented:
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
jatcanCommented:
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
kcarrimCommented:
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
kcarrimCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jatcanCommented:
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
ianmarchantAuthor Commented:
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
ianmarchantAuthor Commented:
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
kcarrimCommented:
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
ianmarchantAuthor Commented:
ok, thats probably what I want then!

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

0
kcarrimCommented:
Yes.
0
ianmarchantAuthor Commented:
sorry for the delay, i've made the change... will i need to reboot for it to take effect?
0
kcarrimCommented:
Any changes to the registry requires a reboot.
0
ianmarchantAuthor Commented:
thanks for the help/suggestions everyone.
0
kcarrimCommented:
Cool!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.