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
I honestly don't know, but I'd have a look at the APM or ACPI APIs.
Other than that, the only option I can think of right now is a USB controlled robotic arm that ejects the battery when you need to stop charging, but that's probably not what you are looking for, and borders on the complicator's glove in terms of level of over-engineering. :)