问题
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.SystemInformation.PowerStatus).
I want to be able to stop a battery from charging based on some criteria, e.g. battery power > 20%.
Is there an API to do this?
回答1:
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.
回答2:
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. :)
回答3:
I think it's possible, because it was patented by IBM (patent no. 7570015).
Not sure if there's a Windows API available for that.
回答4:
One of the options is to get hold of the device(I) for battery (Microsoft ACPI-Compliant Control Method Battery). Listen for PowerNotification events forever. On each notification check the PowerStatus of the battery. There are APIs for all of the above purposes in .Net and win32
Keep the device(I) disabled as long as the powerstatus is >threshold. Enable it as soon as goes below that or when you are not on AC power (i.e. before removing AC power, your continuously monitoring software should enable that battery device - or you manually enable it).
hmm,...this is a very buggy solution, but it can achieve what you want, although you have to be very careful.
回答5:
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...
回答6:
I think MiCTech is right. I dont think it is possible but here are some resources which you might useful.
- Power Management Functions
- RegisterPowerSettingNotification Function
回答7:
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.
回答8:
Lenovo laptops know lets you specify the charging levels from bios or from their software, but this feature must be implemented in bios in order to be accessed from windows.
回答9:
I came to conclusion:
just give up and forget this matter. It is not a problem, so dont worry about that. Let it be plugged in and be fully charged. when it is on 100%, then the system automatically stops charging, and goes on the plug power, so, maybe no worry to wear a battery, as all notebooks (if it's not from the XX century) has auto regulation of it. Although, If you will ever need, move you hands and plug it on/off manually. Dont be lazy. That is the #1 and quickest solution, beleive me.
(however, if you want to waste time, here are methods -
1) http://www.makeuseof.com/answers/what-battery-manager-can-stop-charging-at-a-certain-percentage/
2) disable devices temporarily (But you need to disable "Microsoft ACPI-Compliant Control Method Battery")
3) https://superuser.com/questions/813182/how-to-stopdisable-battery-charging-on-laptop
来源:https://stackoverflow.com/questions/1091775/how-can-i-programmatically-stop-a-notebook-battery-from-charging