Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When did my computer went to sleep the last time? Window 7 [closed]

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.

like image 436
CleanCoder Avatar asked Jan 27 '12 14:01

CleanCoder


People also ask

When did my computer last sleep?

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.

How do I find last wake on my computer?

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.


1 Answers

Have you consulted Event Viewer? To start Event Viewer by using a command line

  • Open a command prompt. To open a command prompt, click Start, click All Programs, click Accessories and then click Command Prompt.
  • Type eventvwr.

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:

  • https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-operatingsystem
  • http://powershell-guru.com/powershell-tip-7-convert-wmi-date-to-datetime/
  • https://www.thewindowsclub.com/find-system-uptime-windows
like image 114
Stephen Quan Avatar answered Oct 20 '22 15:10

Stephen Quan