Hi, @13514180. Welcome Microsoft Q&A. You could use the SessionEnding event to detect when Windows is shutting down and handle it accordingly in your WPF application.
You can also use the Application.SessionEnding event to handle this event in your WPF application.
To prevent the “This app is preventing shutdown” message from appearing when users attempt to restart their PCs, you could modify the Registry by following these steps:
1 . Press Windows key + R to open up a Run dialog box.
2 . Type “regedit” and press Enter to open up Registry Editor.
3 . Navigate to HKEY_CURRENT_USER\Control Panel\Desktop.
4 . Locate the “AutoEndTasks” value on the right-hand side of the window and double-click it.
5 . Change its value data from 0 to 1 and click OK to save changes.
6 . Close Registry Editor and restart your computer to save the changes. This will ensure all software will close automatically as soon as you click the Shutdown button – even if they contain unsaved data.
If the response is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.