Create a Windows Service That Uses a System Tray Icon

Problem

You want to create a Windows service that uses some type of user interface, such as a system tray icon.

Solution

If possible, do not implement any user interface in a Windows service. As a last resort, enable desktop interaction using the Computer Management console.

Discussion

Microsoft guidelines discourage user interfaces with any Windows service application. Adding a user interface can lead to security risks and can prevent the service from running at all if the required permission isn’t granted. In fact, Windows services should be able to run with absolutely no user intervention—there might not even be a user logged on to the computer.

In cases where you do need a user interface to configure ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.