To prevent Windows from shutting down when this happens, you can respond to the WM_QUERYENDSESSION message (you donβt know if you can do this easily with the Python win32 API, but it is simple in C). This may not prevent the closure of applications, as Windows sends WM_ENDSESSION to those who respond TRUE to the request message.
I think you'd rather want to prevent a temporary shutdown with shutdown.exe. I am sure that the program uses InitiateSystemShutdown to show a shutdown dialog, but there are no resources to intercept this call (at least I did not find any or know the Windows function that allows such a thing).
source share