I developed an application that kills a program then restarts it. The only problem is that the system tray contains two icons (or more depending on how many times the applicaiton is killed then restarted). I need to figure out how to either: A) refresh the system tray B) close the program gracefully (the process close() and process closemainwindow() do no work) or C) figure out a way in C# to move the mouse over the system tray programacally to force the ghosted icon to disappear. PLEASE HELP!!!!
Thanks,
Jason

Need to kill a process gracefully
Gus B
I think this is a natural thing/behaviour - sometimes Windows forgets to remove the item from the systray once the app is closed or could be because the application has not correctly removed its icon from systray so next time you hover over I think Windows will check to see if that app is still running/exists
you can programmatically set the mouse position to that place where the Icon is but this would not be a good idea (different screen res, the systray icon could be in a different place, user wont be happy the fact that the mouse has moved automatically etc....)
you can P/Invoke using Shell32.dll with a function/API called Shell_NotifyIcon
http://www.pinvoke.net/default.aspx/shell32/Shell_NotifyIcon.html
but not recommended to P/Invoke unless you REALLLY have to.
sagittarian
holy_spirit
Matt Stum
Here is some vb code to move the mouse along the tray...
http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/3cb9dcf3a93caf35/fee1156a846a6b62%23fee1156a846a6b62
JohnWP
How are you killing the app
I have used Sendmessage with WM_CLOSE in the past without problems (little "genter" when closing an app)
Most methods that "kill" an app...do so without giving the app a chance to "unload" or do cleanup.
yousaid
IreneSmith
I have also tried .CloseMainWindow(); and that just minimises it to the systray. The application in a VPN program - I test to see if the system is on OUR network or not - then in order for it to enable or disable the VPN Firewall - I have to .KILL(); the app - thus lies the problem of the multiple icons.