11

I need to know how long my laptop has been unplugged. Is there a way to do this using cmd or some kind of tool?

2
  • 1
    This information isn't logged my Windows
    – Ramhound
    Commented Jan 10, 2017 at 0:06
  • 1
    Yea, I first looked to see if I could figure out how to tell Windows to log it, because that would be simple and brilliantly easy, just filter for the correct events. But it turns out powercfg does log this information. Commented Jan 10, 2017 at 0:41

2 Answers 2

5

I need to know how long my laptop has been unplugged

Windows doesn't log any events when a laptop is unplugged.

You can however use something like the batch file below and create a custom event.


Battery.cmd

This batch file monitors whether a laptop is currently on mains power or battery power.

It creates a user defined event if the mains is unplugged and the laptop starts to use the battery.

@echo off
setlocal EnableDelayedExpansion
:start
rem get the battery status, 1 = battery discharging 2 = on mains
rem use findstr to strip blank lines from wmic output

for /f "usebackq skip=1" %%i in (`wmic path win32_battery get batterystatus ^| findstr /r /v "^$"`) do (
  set _status=%%i
  if [!_status!] equ [1] (
    rem on battery
    rem create a custom event in the application event log
    rem requires administrator privileges 
    eventcreate /l APPLICATION /t WARNING /ID 999 /D "Mains has been disconnected"
    goto :done
    ) else (
    rem on mains
    rem wait for 10 minutes then try again
    timeout /t 600 /nobreak > nul
    goto :start
    )
  )
:done
endlocal

Notes:

  • The Eventcreate command works on Windows XP up to and including Windows 10, it requires administrator privileges to work
  • If the mains is disconnected an event with ID 999 will be generated in the APPLICATION event log with the description Mains has been disconnected
  • Modify the eventcreate command as required for your situation.
  • Modify the timeout delay as required for your situation.

Example output

When running Battery.cmd and disconnecting the mains power the following output is generated:

> battery

SUCCESS: An event of type 'WARNING' was created in the 'APPLICATION' log with 'EventCreate' as the source.

>

And here is the new entry in the Event Log:

enter image description here


Further Reading

13

You can generate a battery report which will contain this information. It's a manual process good for one-time checks, but not great for on-going repeated checks.

The process is simple.

  1. Open a Command Prompt as Administrator.
  2. Type in powercfg /batteryreport /output "C:\batteryreport.html" and hit Enter.
  3. Open the report file using a web browser.

The report will contain history of the power states of your computer and the power source during that state.

Note: I got this information from a quick Google search and this helpful document which has lots of pictures: http://www.windowscentral.com/generate-battery-report-windows-10 I tested it myself on a Windows 10 tablet running build 1607 (Anniversary Update).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .