There is some easily available information on finding the status of a battery, or weather it\'s charging or not. (GetSystemPowerStatus API or System.Windows.Forms.SystemInformat
But for example Vista won't charge battery if it is unplugged and then plugged while it's capacity is above 96% so it means that in can be accessed and manipulated somehow.
Actually I use such a charge limiter. There is the control software - a Python script that monitors the battery level (psutil module) and controls external hardware - i.e. a switch that can be software controlled. I have Energenie and TP-Link homeplugs plus my own hardware contraption.
As it is for home use the software it's not polished at all, but with minimal effort can be adapted to any OS or hardware.
Let know if interested. The software lives here: CCC
I would just get a UPS and programatically tell it to cut all power... most should have an interface for doing this. Otherwise, as someone already said - a computer-controlled power strip would do it ^^
I've actually played with this idea when I was testing/writing about way too many new laptop models a while ago and the battery testing was annoying to set up, monitor and analyze.
I wrote an app that would do exactly everything (setup, listening, measuring, reporting) except unplugging the power and then replugging it and starting the computer again...
I think it's impossible, because you have need some API for battery or battery charger.
And this API can provide to you manufacturer of notebook and battery or battery charger support this.