AKZap
AKZap

Reputation: 1211

Checking my laptop battery life by VB.NET

In my VB.Net project with framework 2.0, i need to get the current buttery life of laptop or notebook by coding.

It is possible to get the current battery status information?

Upvotes: 2

Views: 10703

Answers (2)

emerald
emerald

Reputation: 329

You can Try This Code

Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox("Percent battery life remaining: " & percent * 100)

Upvotes: 11

Styxxy
Styxxy

Reputation: 7517

Check out the SystemInformation class, more specific, the PowerStatus property (which returns an instance of the PowerStatus class).

Following code will give you the current battery information:

Dim powerstatus As PowerStatus = SystemInformation.PowerStatus

' Gets the current battery charge status.
MessageBox.Show("BatteryChargeStatus : " & powerstatus.BatteryChargeStatus)

' Gets the reported full charge lifetime of the primary battery power source in seconds.
MessageBox.Show("BatteryFullLifetime : " & powerstatus.BatteryFullLifetime)

' Gets the approximate amount of full battery charge remaining.
MessageBox.Show("BatteryLifePercent : " & powerstatus.BatteryLifePercent)

' Gets the approximate number of seconds of battery time remaining.
MessageBox.Show("BatteryLifeRemaining : " & powerstatus.BatteryLifeRemaining)

' Gets the current system power status.
MessageBox.Show("PowerLineStatus : " & powerstatus.PowerLineStatus)

Upvotes: 8

Related Questions