Question How do I show a Windows service-driven program in the System Tray?

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi, all. I have a VB2005 app called (say) MyService.exe which successfully runs as a Windows service. I have the VB2005 app. called (say) MyApp.exe which this calls successfully, I know this because various log files are produced at the right times.

I can run MyApp.exe as a non-service standalone exe - it is designed to show in the System Tray even though it is not of itself a Windows service.

When MyApp is run from the MyService service, it does not show in the System Tray.

How can I get MyApp to show in the System Tray when running it from within the MyService app?

Thanks in advance.
 
The windows services system is designed to be sealed from the user desktop, you have to enable "interact with desktop" to override this. I recommend you don't and rethink the design. For example can you have the tray UI app start when user log in and sit idle until contacted by the service. Or only let service interact with the UI tray app if user chooses to by actively running it, otherwise the service can do its job silently and keep quiet.
 
This project is for an unattended server somewhere deep in the basement of a large company. There will not normally be a user to log in to begin the program, unless there is a fault and the user needs to attend for some reason. If a reboot happens eg. after a power cut, the service should start again without a user logging in.

You mentioned 'Interact with Desktop' - is that a property which can be set somewhere? I looked but didn't see anything like that.

Might it be because MyApp is already set to show in the System Tray, that somehow this causes it not to when part of a windows service?
 
s that a property which can be set somewhere? I looked but didn't see anything like that.
Control panel, Administration, Services. Service properties, Log On options.
Might it be because MyApp ... causes it not to when part of a windows service?
No, the service runs in an environment that has no contact with the desktop environment you see as an interactive user. Both can access same file system and sockets etc.
 
What John means is, ideally you should write another program that contacts the service via e.g. remoting, in order to administer it. You should not build the admin forms etc into the service.

Consider a web interface; most of my services have a basic web interface implemented using an HttpListener, thus they can be administered by any computer having a web browser
 
Back
Top