Swinders
Swinders

Reputation: 2291

How can I get my Windows Service to display in the system tray?

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.

Upvotes: 7

Views: 7174

Answers (4)

Wim Haanstra
Wim Haanstra

Reputation: 5998

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.

Upvotes: 2

David
David

Reputation: 25470

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.

Upvotes: 11

Jakob Christensen
Jakob Christensen

Reputation: 14956

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.

Upvotes: 5

kemiller2002
kemiller2002

Reputation: 115538

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.

Upvotes: 2

Related Questions