cwinapishutdownapplication-shutdownsystem-shutdown

How to write a program that stops the shutdown process by C?


Programs like Notepad can stop the computer shutdown process when files are not saved. How can I write a program that stops the shutdown process (in C)?


Solution

  • For Windows Vista and above there exists a fuction defined in User32.dll (User32.lib) called "ShutdownBlockReasonCreate".
    It takes two parameters:
    - A handle of the window
    - A string representing a message to be displayed
    If the call succeeds than you application will block windows from shutting down.

    This is a powerful function and should not be abused!