Is there a way to find out when the system was last shutdown?
I know there's a way to find out last boot up time using the LastBootUpTime property in Win32_OperatingSystem namespace using WMI.
Is there anything similar to find out last shutdown time?
Thanks.
Assuming Windows is shutdown smoothly. It stores it in the registry:
It is stored as an array of bytes but is a FILETIME.
While there may be a better way, I have used this before and think it works:
(everything here is 100% courtesy of JDunkerley's earlier answer)
The solution is above, but the approach of going from a
byte
array toDateTime
can be achieved with fewer statements using theBitConverter
.The following six lines of code do the same and give the correctDateTime
from the registry:Last Restart time can be found using this piece of code