I wanted a windows service I'm building to run overnight. So I changed my power options and set my computer to never sleep. Started the windows service and went home. This morning I found my computer sleeping and was curious if someone manually put it to sleep after I left. Is there a log file or some way to find the last time my computer went to sleep? I'm using a Windows 7 operating system.
In Event Viewer, you need to go to Windows Logs > System. Scroll down to find the Power - Troubleshooter option and click it to open it. In the General tab, you can see what woke up your computer in the Wake Source You can also find some other information like Sleep Time and Wake Time.
To find out what is causing your computer to wake up, open Command Prompt as an administrator and type in powercfg/lastwake. Then type powercfg/waketimers to find out if you have any wake timers on. Click the magnifying glass icon in the bottom-left corner of your screen.
Have you consulted Event Viewer? To start Event Viewer by using a command line
Information about scheduled / unscheduled sleeps and reboots should be found by expanding the tree view in the left plan to Event Viewer > Windows Logs > System.
You can also get the last boot time by using the WMI service object to query the LastBootUpTime property of the Win32_OperatingSystem class. Note that the returned date is in WMI date time format which you'll need to use tools to convert into a human readable date.
Here's a VBScript sample:
' LastBoot.vbs
Option Explicit
Dim wmiService, objDateTime, OS
Set wmiService = GetObject("winmgmts://localhost/root/cimv2")
Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")
Set OS = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem").ItemIndex(0)
WScript.Echo OS.LastBootUpTime ' Example: 20180801131622.495364+660
objDateTime.Value = OS.LastBootUpTime
WScript.Echo objDateTime.GetVarDate ' Example: 01/08/2018 12:16:22 PM
Here's a PowerShell example:
(Get-WmiObject Win32_OperatingSystem).LastBootUpTime
# Outputs: 20181009160558.495300+660
(gcim Win32_OperatingSystem).LastBootUpTime
# Outputs: Wednesday, 1 August 2018 12:16:22 PM
Here's a Command Prompt example (uses PowerShell):
powershell -command "(Get-WmiObject Win32_OperatingSystem).LastBootUpTime"
REM Outputs: 20180801131622.495364+660
powershell -command "(gcim Win32_OperatingSystem).LastBootUpTime"
REM Outputs: Wednesday, 1 August 2018 12:16:22 PM
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With