Click here to Skip to main content
15,882,464 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
While I click on the turn off option, I would like show a message box with Yes/No Option. It should be shown with the help of Windows Service.

Could u pls, direct or give source code for the above problem?

You could do this-

in your coding before shutting down check the messagebox result

DialogResult result = MessageBox.Show("Do you really want to shut down?",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);

if (result == DialogResult.Yes)
// Code for shutdown
Share this answer
Windows service in itself does not support any UI.
The best you can do is catch the stop event[^] of the service and then launch an exe that will display a message box.

However if the machine is already shutting down, the message box will be closed by the operating system anyway.

A better approach would be to handle WM_QUERYENDSESSION or WM_ENDSESSION on your own as described here[^]. You can do
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900