I am building an Excel alarm clock for a laptop. I am updating the display
with an OnTime event. One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.
Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?
Thanks for any leads.

Signature
Gary''s Student - gsnu200766
John Bundy - 25 Jan 2008 14:29 GMT
Sorry i don't know who to give credit to as i found this some time ago and
modified it. Enjoy!
Declare Function GetSystemPowerStatus& Lib "kernel32" (lpSystemPowerStatus
As _
SYSTEM_POWER_STATUS)
Type SYSTEM_POWER_STATUS
ACLineStatus As Byte
BatteryFlag As Byte
BatteryLifePercent As Byte
Reserved1 As Byte
BatteryLifeTime As Long
BatteryFullLifeTime As Long
End Type
Public SysStat As SYSTEM_POWER_STATUS
Public Ret As Boolean
'***************************
' Place in command button click
Private Sub Command1_Click()
Ret = GetSystemPowerStatus&(SysStat)
MsgBox Ret
MsgBox "AC Status = " & SysStat.ACLineStatus
End Sub
'*****************************
Ret is True if successful.
ACLineStatus =0 if offline (battery?), 1 if online (AC Power, also desktop),
255 if unknown (Aliens?)

Signature
-John
Please rate when your question is answered to help us and others know what
is helpful.
> I am building an Excel alarm clock for a laptop. I am updating the display
> with an OnTime event. One of the requirements is to autonomously detect if
[quoted text clipped - 4 lines]
>
> Thanks for any leads.
Jim Cone - 25 Jan 2008 14:32 GMT
Maybe...
Private Declare Function GetDevicePowerState Lib "kernel32.dll" _
(ByVal hDevice As Long, ByRef pfOn As Long) As Long
http://msdn2.microsoft.com/en-us/library/aa372690.aspx
Private Declare Function GetSystemPowerStatus Lib "kernel32.dll" _
(ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
http://msdn2.microsoft.com/en-us/library/aa372693(VS.85).aspx

Signature
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
"Gary''s Student"
wrote in message
I am building an Excel alarm clock for a laptop. I am updating the display
with an OnTime event. One of the requirements is to autonomously detect if
the laptop switches from A/C power to its internal battery.
Has anyone come across an API that will return the power state? Say TRUE if
A/C, FALSE if battery?
Thanks for any leads.
--
Gary''s Student - gsnu200766
Gary''s Student - 25 Jan 2008 14:46 GMT
Thank Jim (once again) !

Signature
Gary''s Student - gsnu200766
> Maybe...
>
[quoted text clipped - 5 lines]
> (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
> http://msdn2.microsoft.com/en-us/library/aa372693(VS.85).aspx
John Bundy - 25 Jan 2008 14:34 GMT
Actually this looks to be the link and it contains some more info, about 2/3
the way down.
http://www.codeguru.com/forum/archive/index.php/t-199354.html

Signature
-John
Please rate when your question is answered to help us and others know what
is helpful.
> I am building an Excel alarm clock for a laptop. I am updating the display
> with an OnTime event. One of the requirements is to autonomously detect if
[quoted text clipped - 4 lines]
>
> Thanks for any leads.
Gary''s Student - 25 Jan 2008 14:46 GMT
Thanks John!!

Signature
Gary''s Student - gsnu200766
> Actually this looks to be the link and it contains some more info, about 2/3
> the way down.
[quoted text clipped - 9 lines]
> >
> > Thanks for any leads.