views:

40

answers:

2

Hi guys,

i work with windows server 2003 (and 2008) and C#, i have a problem with systray of the desktop.I have done an application for disk managment and when the application start, it hide itself from taskbar and adds an icon in the systray. When i click on this icon (in the systray) the Form of the application is showed.

I have created a task in the system scheduler to execute automaticaly the application at a specific time, if i'm logged on the server when the application is lunched (from the scheduler), the icon appear in the systray of the desktop. But if i'm not logged on server and the scheduler lunch my application, when i log on i can't see the icon in the systray, but my application working perfectly.

I tryied different ways to show the application form, example, the application read a flag in a file and when the flag is true it forces the form.Show() but don't work.

I suppose i have to notifiead my application form to explorer (process) when the desktop is loaded but i haven't idea how do this. It's corrent way? I'm waiting for yours advice.

Best Regards

+2  A: 

I suppose that this is due to the fact that when nobody's logged in, there is no desktop session to run the application in.

Even though the application may work fine, it is not running under the user that logs in later, so you can't see the icon. It is running as a different user "in the background".

This is effectively the same as when two users are logged in using Remote Desktop. One can start an application that creates a systray icon, the other user will not see that icon.

One alternative would be to put the application's logic into a windows service. Then, I'd create a client that auto-runs when a user logs in, checks whether the service is currently active and shows the icon and the form.

Thorsten Dittmar
+1  A: 

When your application launches whilst you are not logged-on, there is no Desktop context, so your code to display the icon on the System Tray essentially 'fails' silently - the messages to site the icon are sent, but there's nothing there listening to them, and of course no-one looking anyway.

When you subsequently log-on and create a Desktop context, your app is already running and has no way of knowing (yet) that there is now a visible desktop to register the icon with. It did the icon registration when it started, and as far as it is concerned that part of the job is done.

So you need a way to tell the app that you're there with a Desktop and a System Tray ready to have an icon in it, and the app then needs to repeat the icon registration process. If you don't want to separate the core logic from the presentation layer by creating a service/client arrangement, you could instead have your app in the Startup group so that it runs when you log on.

You don't want two copies running, so tweak the app to check for other instances of itself, and if there is one to switch focus to it and kill itself. Then, in the focus-handler, disable and then re-enable the icon tray registration to re-send those messages.

Jonners