Run something if battery is (dis)connected

Martin Brinkmann
Jan 23, 2008
Updated • Nov 30, 2012
Mobile Computing

It may sometime happen by accident that the power cable connecting the power source to your notebook gets disconnected while you work with the mobile computer. It does not have to be by accident though, maybe you want to use the notebook in a different location without having to save everything and boot again. The problem that comes up in this situation is that the notebook will start running on battery instead, which can be a issue if it was not charged fully in first place. If the notebook gets disconnected from the power source at an inappropriate time, it may happen that it powers down immediately.

Battery Run is a little command line utility that checks if a power cable is connected. Once it notices that the power cable has been disconnected, it starts a user defined action. A second action is run when the notebook is connected to a power source again. You could for instance play a sound if the power cable gets disconnected to notify you that this just happened, or a software that would reduce power consumption.

Usage is straightforward. Download and unpack the file on your hard drive. Use the command batteryrun load-program-when-disconnected load-program-when connected. For example: batteryrun disconnected.wav connected.wav

Batteryrun will play the disconnected.wav file when the power cable gets disconnected, and the connected.wav file when it gets connected again. A icon should appear in the system tray if everything has been setup correctly.

You can obviously run different programs, or even send the program directly into hibernation or sleep mode to save battery until you can connect the PC to a power source again.

Battery Run is a free portable program for the Windows operating system. It is compatible with all recent 32-bit and 64-bit editions of the operating system.


Tutorials & Tips

Previous Post: «
Next Post: «


  1. yair said on January 23, 2008 at 12:44 pm

    i use an old laptop to run a 3 year unattended time-lapse photography. it is connected to UPS.
    if i have severe power failure i need to run a notification when the ups fails and the battery kicks in.
    i use gcal command line utility to send an sms.
    anyways this is exactly what indeed…

  2. duryodhan said on January 23, 2008 at 5:20 am

    All of the notebooks I have used, you can see a noticeable difference in screen brightness as soon as the ac power is connected and a sound is also played. A light on the laptop also turns off.

  3. yair said on January 23, 2008 at 2:39 am

    just what i needed, thanks!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.