How do you record Laptop Battery Level?

ryodoan

Well-known member
Joined
Jul 16, 2004
Messages
65
Location
Ohio
Programming Experience
3-5
I have a few questions, just for fun I wanted to be able to create a chart of my laptop level throughout a normal day saving the battery level every 5 minutes or so, but as of right now i need some pretty large pointers.

  1. The main question is there in the title, how do you access the laptops battery level?
  2. At the moment I do not know how to make a program that runs constantly in the background, how would I do this? Got a link to a guide, I would love it.
  3. Are there any easy ways to create a chart in VS.net? or am I best off just exporting a tab delinated text document and then doing something in excel to see what was going on?
Thanks for any help yall can give me.
 
Here's how i would do the first part, if there is a native .net way to do this then that would be preferred, but i don't know of one...

VB.NET:
<StructLayout(LayoutKind.Sequential)> _ 
Private Structure SYSTEM_POWER_STATUS
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Int32
Public BatteryFullLifeTime As Int32
End Structure
 
Private Declare Function GetSystemPowerStatus Lib "kernel32" (ByRef lpSystemPowerStatus As 
SYSTEM_POWER_STATUS) As integer

For the second point you need to look into 'windows services' have google for it there should be a few tutorials about.

I'm afraid creating a chart is just not an easything to do. You'll need a fair bit of knowledge about GDI+, and you may even need to solve the occasional quadratic equation. I'm not trying to put you off, it's just that there are a number of charting tools out there, so why re-invent the wheel?
 
thank you very much for the help, it is exactly what I needed, still looking into the graphing but I think I will be able to handly it from here, thanks.

One final question, I figured there would be a windows api function that would let me find the battery status, I seem to recall there is a website that lists all of them, but I forgot to bookmark it and I couldnt find it, any idea where I could find such a website?
 
There may well be a site that lists them but there is a better way. A little program called API viewer here's a link to it.....

http://www.activevb.de/rubriken/apiviewer/index-apiviewereng.html

Don't forget to set the compatibility to VB.net in th options. Also it is always preferred to use native .net methods, and you should only resort to Win32 API's if there is no other alternative.
 
Back
Top