I'm used to not shutdown Windows but to sleeping it. I set up power button (PB) action to do it. When I want to shutdown I must go to start -> Shutdown. That's OK.
Now I think of a mechanism that will be hooked up to a PB. Should be started after I press PB but before OS will go to sleep. Something that will check few conditions (i.e. running backup, running AV scan, ...) and if true (something is running) prevent go to sleep.
Optionally: It would be nice to start the same "mechanism" before restart and shutdown (invoked not only from Start menu, but also by other software (i.e. installers) but with option to allow some sources (i.e. UPS software)
Generally: How to run something after PowerButton but before Sleeping. How to code (C#.NET, vbs, batch (preferred)) sleep prevention (cancellation).