Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a message box from a Windows Service

Tags:

Can you display a message box (or any form of notification) from a windows service? Can't get it to work. I used:

            global::System.Windows.Forms.MessageBox.Show("A fatal error occurred. " +
                ServiceName + " is now terminating.");

but it didn't work and just produced an error.

like image 482
Jonn Avatar asked May 07 '10 06:05

Jonn


People also ask

How do I display message box?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

What is message box control?

a title that can represent the source of the message. an icon for each message type to determine how critical a message box is. a brief text message. some command buttons that can represent a user decision.


2 Answers

No, you cannot show a message box from a service. If you want to report errors, the standard way to do this is with the event log.

For more "advanced" kinds of UI (not just error reporting), the way this is typically done is via a regular windows application that you put in the user's Startup folder (or the Run key in the registry) and that talks to the service via some kind of IPC mechanism (.NET remoting, WCF, regular sockets, named pipes, etc).

like image 145
Dean Harding Avatar answered Oct 24 '22 22:10

Dean Harding


You can display a message from a service with "WTSSendMessage(...)" function (which is available since Windows Vista and Windows Server 2008), here is a good article: http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx

like image 33
Mike Avatar answered Oct 24 '22 23:10

Mike