title: Shut down Windows programmatically and wait for termination of resident processes
body: <h2>Background</h2>
  <ul>
  <li>I am writing a program to shut down Windows at the specified time. I am using <code>shutdown.exe</code> to implement this function.</li>
  <li>In my computer, there is a resident process to record system activity and send the record to a server when shutting down Windows. When you shut down Windows from the start menu (<code>RuntimeBroker.exe</code>), Windows waits for the resident process to finish sending the record (according to <code>HKCU\Control Panel\Desktop\HungAppTimeout</code>).</li>
  </ul>
  <h2>Problem</h2>
  <p>When I shut down Windows with <code>shutdown.exe</code>, it doesn't refer to <code>HKCU\Control Panel\Desktop\HungAppTimeout</code> and kills the resident process forcibly before it finishes sending the record.</p>
  <h2>Question</h2>
  <p>Is there any way (like a PowerShell cmdlet or a command included in Windows) to shut down Windows programmatically and wait for the termination of the resident processes gracefully before the shutdown?</p>