10
2
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?
10
2
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?
4
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.
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:
Eventcreate
command works on Windows XP up to and including Windows 10, it requires administrator privileges to work999
will be generated in the APPLICATION event log with the description Mains has been disconnected
eventcreate
command as required for your situation.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:
9
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.
powercfg /batteryreport /output "C:\batteryreport.html"
and hit Enter.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).
1This information isn't logged my Windows – Ramhound – 2017-01-10T00:06:31.873
1Yea, 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. – music2myear – 2017-01-10T00:41:08.807