See the
Form.FormClosing event[
^]
Check the CloseReason property of the FormClosingEventArgs, if it is CloseReason.WindowsShutDown then set e.Cancel to True then it should prevent the form closing immediately.
Then, you can stop shutdown by using
Process.Start("shutdown", "-a")
I haven't tried this in Win8 or Win10, but it should still work.