title: Working with a shut-down state of a user session on Windows?
body: <p>Say, if I open a Notepad, type something in it and don't save it, then call the following API from the same user session:</p>
  
  <pre><code>ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED);
  </code></pre>
  
  <p>That user session will enter a "shut-down state", where OS will show an overlay window displaying a message that Notepad prevents system from logging off a user. This overlay will not go away until a user clicks "Cancel" or "Force Quit" buttons.</p>
  
  <p>So two part question:</p>
  
  <ol>
  <li><p>Is there any way to know which processes blocked logging-off/shut-down process?</p></li>
  <li><p>Is there any way to cancel this user-session "shut-down state" programmatically?</p></li>
  </ol>
  
  <p>PS. This state can be detected by calling GetSystemMetrics(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx#SM_SHUTTINGDOWN" rel="nofollow noreferrer">SM_SHUTTINGDOWN</a>);</p>
  
  <p><strong>EDIT:</strong> Contrary to the answer below, I <em>am not</em> trying to stop system from shutting down, nor that any user-mode process is "hung."</p>
  
  <p><strong>EDIT2:</strong> Here's a screenshot of the overlay I'm trying to cancel/close:
  <img src="https://i.stack.imgur.com/xNhvG.png" alt="enter image description here"></p>