How can I find out when my laptop was last unplugged in windows 10?
Solution 1:
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 descriptionMains 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:
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- eventcreate
- Using Windows PowerShell to Determine if a Laptop Is on Battery Power
- wmic - Windows Management Instrumentation Command.
Solution 2:
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.
- Open a Command Prompt as Administrator.
- Type in
powercfg /batteryreport /output "C:\batteryreport.html"
and hit Enter. - 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).