Preventing Logoff / Shutdown until C# Windows App is closed

M

mikemiller.innova

I developed a C# Windows App that requires a user to input their real
name and what they did to the server while they were online.

I am going to launch the app att shutdown via a logoff script.

I want to prevent the computer from logging off or shutting down until
the app is closed.

The best example I have is when you have an unsaved notepad.exe
document open and logoff or shutdown, an End Program dialog pops up
that says "The system cannot end this program because it is waiting for
a response from you". The computer will sit there forever waiting for
user response. I want that to happen with my app so they are forced to
enter data before the logoff/shutdown process continues.

How can I do this?
 
M

mikemiller.innova

I had to figure it out myself...

With a form called 'Form1', you can use this code to do it:

(bSubmitted is a boolean that gets set to TRUE after the app submits
an entry)

private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
if (bSubmitted == false)
{
if (MessageBox.Show("You are closing this app without
submitting an entry.\n\nAre you sure you wish to exit without
submitting?", "Warning: Not Submitted", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Stop) == DialogResult.Yes)
return;
else
e.Cancel = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top