How to allow Windows Shutdown my WPF application?

13514180 0 Reputation points
2023-04-18T08:22:52.1833333+00:00

Greetings, Is there a property within WPF applications that will allow Windows to force shutdown the application when trying to do a Windows Shutdown or a restart? When my applicaiton is running and users attempt to restart their PCs they get a message from Windows saying "this app is preventing Windows shutdown". Any suggestions to avoid this?

Developer technologies Windows Presentation Foundation
Windows for business Windows Client for IT Pros User experience Other
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2023-04-19T03:13:39.16+00:00

    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. User's image

    3 . Navigate to HKEY_CURRENT_USER\Control Panel\Desktop. User's image

    4 . Locate the “AutoEndTasks” value on the right-hand side of the window and double-click it. User's image

    5 . Change its value data from 0 to 1 and click OK to save changes. User's image

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.