Microsoft KB Archive/244651

{|
 * width="100%"|

HOWTO: Creating a Shell Notification Icon from a Windows NT Service

 * }

Q244651

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * the operating system: Microsoft Windows 2000

SUMMARY
When developing a Windows NT service, it may be desirable for the service to create a notification icon in the taskbar's notification area to notify the logged on user of the state of the service.

MORE INFORMATION
Notification icons are added, modified and deleted using the Shell_NotifyIcon API. Since Shell_NotifyIcon relies on windows messaging to communicate with the taskbar, there are some limitations on calling Shell_NotifyIcon from a service.

Services run on a desktop separate from the interactive desktop. One restriction on desktops is that window messages cannot be sent between desktops which would prevent Shell_NotifyIcon from communicating with the taskbar. In order to avoid this restriction the service needs access to the interactive desktop. This can be accomplished by using the SERVICE_INTERACTIVE_PROCESS flag when installing the service, by calling CreateService, or changing the service's configuration, by calling ChangeServiceConfig.

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

"Q173687 HOWTO: Access the Application Desktop from a Service" Once the service has access to the interactive desktop, the service must know when to call Shell_NotifyIcon to create the notification icon. Assuming that the taskbar has already been created, the service can call Shell_NotifyIcon when the service starts. A problem occurs if the taskbar has not been created, for example when there is no user logged on interactively. In this case, Shell_NotifyIcon fails to create a notification icon. The service would then need to be notified when the taskbar is created so it can successfully call Shell_NotifyIcon. A notification is sent in the form of a registered window message, "TaskbarCreated", that is broadcast to all top-level windows when the taskbar is created. The service can then create the notification icon when handling this message.

An alterative approach to creating the notification icon from a service would be to create a second application that is started when a user logs on the system. This application would create the notification icon and communicate with the service through some IPC mechanism or with the Service Control Manager to determine the state of the service.

Windows NT 4.0 only: The "TaskbarCreated" message is only sent on shell version 4.70 and later. Earlier versions of the shell do not send this notification. Shell versions prior to 4.70 can be updated by installing Internet Explorer 4.x with the Desktop Update.