views:

868

answers:

4

I have a Windows Service that runs in the background when the PC starts. I want to display an Icon on the system tray to allow configuration after a user has logged in but can't find how to do this.

Is there an event I should be looking for which tells me that a user has logged in?

As I understand Windows Services can't have a UI so do I need to start an app to display the sys tray icon? How can I pass configuration updates to my service.

+2  A: 

I would create a second application that runs and displays itself in the system tray when the user logs in.

You can open remoting to the windows service, and pass the configuration updates through exposed methods from the app in the system tray.

Kevin
+4  A: 

You will need a separate application to show the tray icon. You can communicate with your service either through WCF letting the service host a WCF service or through ServiceController.

Jakob Christensen
+8  A: 

You will want a seperate "agent" application for this. A Windows service is global, running at the system level. There can be multiple desktops running on the system at once, so while there are ways of allowing services to interact with the desktop layer, it is far from trivial to interact with the "users desktop" in the same manner that you do with an application already bound to a specific login/desktop environment.

There are also security risks involved with having a service tunnel into the desktop environment (it opens up a pathway to a system account unless the service runs on a more restricted one), which is why interacting with the desktop is disabled by default.

David
+2  A: 

Actually, I don't think you CAN show a service in the system tray. Applications doing this are always using an agent or other mangement tool.

Most of the time the application running in the tray is a very small app giving access to the settings for the service.

Configuration options could be stored in the registry, ini file or anyother storage option. After the configuration changes, all you need to do is make sure you restart your service, so it can reload it's new settings.

Wim Haanstra