Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys,

I need to know if there was a Windows reboot since the last run of my program. How can I do this this?

It doesn't even matter if is just a startup.

Updated 4-Jan-11 10:16am
Keith Barrow 4-Jan-11 15:57pm    
Minor edit to improve grammar.

The most trivial solution is when your program starts it reads the uptime of the computer. From that and the current date you calculate the last boot time.
Then you read a file in your apps directory that is used to store the last boot time and compare the value you computed with that.
When the program is installed the file in your apps directory gets initialized with the last boot time.

That would be it. Still have doubts? Leave a comment then.

Best Regards,
Share this answer
manchukuo 4-Jan-11 16:38pm    
I will go with your idea Manfred, because the Windows Shutdown event one can be disabled, thanks.
This [^]articles explains how to track the Windows Shutdown.

Obviously, in addition to this your application should also handle and track its own run.
Share this answer
You can use the RunOnce registry key to detect when a user logs in but his can happen without necessary being caused by a reboot. Probably the safest way would be to look for the shutdown event then add a key to the registry which you can check after starting your app.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900