How can I show a Notification Area Balloon and Icon from a Windows Service?
Asked Answered
G

3

6

I have a Windows Service that is always running when the user starts their workstation. This Windows Service is critical and I would like to show a Balloon Notification in the Notification Area when certain things happen such as the Service Stops, Starts, Restarts etc.

For example:
enter image description here

Also, is there a way to show a Notification Area Icon for my Windows Service?

Groff answered 1/6, 2011 at 16:35 Comment(1)
This post might help: #2652754 A service can't directly have a SysTray icon.Hawthorn
U
12

The days of Windows services interacting directly with the desktop are over, so you have to find another way.

What I have done is create a normal WinForms application that includes a NotifyIcon. The behavior of this application mimics that of Task Manager, such that it can be hidden from the task bar and only visible in the system tray. If I right-click the system tray icon, I get a menu. If I double-click the icon, the application window is shown.

To facilitate the communication between the WinForms application and the Windows service, I use WCF. Specifically, I use Juval Lowy's Publish-Subscribe Framework, which works really well for this kind of scenario. See my answer here for more details.

Hope this helps.

Undesigning answered 1/6, 2011 at 17:7 Comment(0)
F
-1

If you just want to send a simple command to your Windows service you can send it a message from your user app in the following way.

ServiceController myService = new ServiceController("YOUR Service Name");
myService.ExecuteCommand(123); // do something;

If you override the OnCustomCommand method in you class the extends ServiceBase. You could then use this command to trigger the service to do somthing like reload a config file, or switch to some state.

Feints answered 18/7, 2011 at 14:52 Comment(2)
Your answer doesn't really mesh with the question. Ryan is trying to work with a System Tray Icon, not send commands to the service.Whiten
What myself and Matt are saying is that rather than configuring you service to detect a user log in and add an icon to their task bar. Have an application that runs separately that puts an icon in the taskbar. This application can access the state and send simple commands to the service in the method show above. That way the icon doesn't disappear if the service terminates. If you want it to be there when the user logs in then add a shortcut to your app to the start-up folder.Feints
P
-1

Our new (and free) ServiceTray utility will let you control your service from a tray icon. It will also show pop-up/balloon notifications when it detects that your service has changed state (started-> stopped, etc).

Plump answered 29/3, 2013 at 15:43 Comment(1)
I'd recommend rewriting this from pure spam/link-only post to some real answer that explains what should be done to implement such functionality... or just delete.Circumsolar

© 2022 - 2024 — McMap. All rights reserved.