Add support for PRE_SHUTDOWN service control signals

See commit messages for details.
Still can't assume you can write to C:/ - and should use properly temporary filenames.