Prevent Agent computer shutdown while build is running

We use our developer's computers to run Agents in background - I think this is a rather common practice.
The problem is that it's not obvious, whether computer is currently running some build.

I would like to prevent Windows shutdown while build is running - starting from Vista there is a really nice way to do so.
This should be a plugin, providing "Additional Build Feature" (like Swabra) with the single option - message text.

Implementation for Windows Vista is extremely simple: just call ShutdownBlockReasonCreate(hWnd, pwszReason). Dual ShutdownBlockReasonDestroy should be called when build has finished. That's it.
Bonus-feature is to call SetProcessShutdownParameters(0x3FF) - ask Windows to query our program before starting to close any other applications.
Ideally, that 20-lines-of-code application should be implemented as reusable JNI-library.

In the end, there will be completely transparent and nice behaviour for an end-user:
- User decides to go home and closes his documents
- User clicks Shudown in Windows
- If build is currently running, clearly-looking warning appears
- There is an option to force the shudown or cancel
- If user does nothing, shutdown will continue once the build has finished

I guess, the easiest proof-of-conept implementation is to start shutdownguard.exe from AgentLifeCycleAdapter and terminate its process when build is finished.
I'd love to see such plugin as a part of TeamCity!


Please sign in to leave a comment.