I d like to know what is the Windows API function (if any exists) that provides information about the last Windows reboot source. There are three main possible causes:
- The computer crashed on a blue screen
- A user or a program shutdown/restarted the computer
- A power lost
The more details I can get the better. However, I need to know at least which reason it is from the main ones.
I need to support Windows Vista and Windows 7.
Answer:
It seems that there is no direct API to get that information. Instead, we have to harvest the Windows Event Log. System reboot information is located in Event Viewer/Windows Logs/System. Here is the various information provided by the event ids:
- 6005: Windows start-up
- 6006: Windows shutdown (properly)
- 6008: Windows shutdown (unexpectedly)
I do not yet get the difference between power lost and system crash, but it s a good start.