Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my program know that Windows was rebooted for updates

Tags:

c#

winapi

When Windows automatically installs updates and automatically restarts, some programs (like Microsoft Word) come back up automatically and restore their original state (Word opens the same documents that were open previously). How can my program do this? Is there an API?

If it is a regular user-initiated restart I do not want my program to come back automatically - that would look weird to the user. But if the user leaves my program open when they go to bed and Windows reboots for updates in the middle of the night, I want the user to come back to their computer in the morning and still see my program running.

I care about Window 7 and above. I tagged the question as C#, since this is the language I am using, but if there is a solution in C/C++, I'll write appropriate glue code and post it here for others to use, too.

like image 337
George Avatar asked Jan 29 '26 23:01

George


1 Answers

begin from vista we can use for this single call

RegisterApplicationRestart(L"some cmd line", RESTART_NO_CRASH|RESTART_NO_HANG);

if we run under XP, we can (as @GSerg propose) listen for WM_ENDSESSION message with

wParam != 0 && (lParam & ENDSESSION_CLOSEAPP) != 0

and register self restart under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce (but not under Run !)

explorer.exe on any next start handle this by delete value key and exec application.

like image 165
RbMm Avatar answered Jan 31 '26 12:01

RbMm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!