Search code examples
c#windowswinformswindows-update

How to restart my application if Windows Update forces a reboot?


At the office, when I leave for the night I very rarely log off or reboot. I simply lock my workstation and go home, leaving all my development tools exactly how I left them.

If Windows-Update rolls through and reboots my machine in the middle of the night I'm only slightly peeved because when I log back in the next morning, any MS Office application, or Visual Studio instance I had running will have already automatically restarted, opening whatever file(s)/projects/solutions I may have been working on.

My question is: How can I make my Windows Forms applications (C#) do this? Is there some way for my application to "register" that it wants to be restarted if the system automatically reboots?


Solution

  • I think the RegisterApplicationRestart Win32 API function might be what you're after, it's part of the Restart Manager API.