Note that there are some explanatory texts on larger screens.

plurals
  1. POWM_QUERYENDSESSION is causing me problems
    primarykey
    data
    text
    <p>Making a simple application, so when the user logs out of Windows, it of course shuts the application down. We are making a simple USB Alert application which STOPS shutdown if a USB is detected when the user is logging off</p> <p>This is the code so far.</p> <pre><code>public Form1() { InitializeComponent(); } private static int WM_QUERYENDSESSION = 0x11; private static bool systemShutdown = false; protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_QUERYENDSESSION) { //MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot"); systemShutdown = true; m.Result = (IntPtr)0; } // If this is WM_QUERYENDSESSION, the closing event should be // raised in the base WndProc. m.Result = (IntPtr)0; base.WndProc(ref m); } //WndProc private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (systemShutdown) { systemShutdown = false; bool hasUSB = false; foreach (DriveInfo Drive in DriveInfo.GetDrives()) { if (Drive.DriveType == DriveType.Removable) { hasUSB = true; } } if (hasUSB) { e.Cancel = true; MessageBox.Show("You still have USB device plugged in, please unplug it and log off again"); } else { e.Cancel = false; } } } </code></pre> <p>What is happening is that the Windows Force Programs to Quit screen is being displayed, I read somewhere if you return 0 to WM_QUERYENDSESSION it does not display this, but it is still displaying this...</p> <p>Any ideas?</p> <p>EDIT:</p> <p>We used the code that someone responded with, but we are still getting this screen.</p> <p><img src="https://i.stack.imgur.com/KzwMo.png" alt="The screen we want to avoid!"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload