To detect and prevent shutdown the computer I use very simple program. It has only one form and one private procedure like below:
TForm3 = class(TForm) priva
ShutdownGuard is built with Delphi and it's open source, you can download it tweak it for your needs