Windows Service Beep on Windows 2008/7 / Vista

This question has been asked before, but there is no final answer.

I wrote a Windows service in Delphi, which should generate an audio signal under certain conditions. This works fine on XP, but does not work on Windows 7 or 2008.

Note:

  • The sound signal may work if I create a console program instead of a service - using the PC speakers.
  • The sound signal cannot work in the service, even if I turn on โ€œallow the service to interact with the desktopโ€ or even assign administrator rights to this service.

My question is: is there a way that I can call the beep API so that it works in the service? Thanks.

+4
source share
2 answers

You cannot do this in Vista or higher. Services run in a different session and therefore do not have access to the speaker.

+1
source

Update: Someone found a way here . It includes IOCTL and is available to drivers and services.

Original answer:

The only way I know with the user is to associate your service with a small user agent process that will be added to HKEY_LOCAL_MACHINE \ CurrentUser \ Run for autorun.

This is a common template in vista and win7, where user interaction is not possible directly from the service:

  • MyLittleService.exe has no access to the user. But it can communicate through a named pipe using a utility with a tray icon.

  • MyLittleTrayIcon.exe communicates with the service, and it can also transmit a signal to the user with messages, an audio signal through any method (Windows sound effects are likely to be better than trying to access the PC speaker, which is no longer guaranteed on every PC) and etc., and perhaps even can be used to manage the service (restart it, reload the configuration, etc.).

+1
source

All Articles