PC Review


Reply
Thread Tools Rate Thread

Detect power status of laptop

 
 
Jacob Thastrup.com
Guest
Posts: n/a
 
      12th Aug 2004
Hi

How do I detect whether my laptop is running on battery or using the
power outlet?

Thanks

Jacob Thastrup
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      12th Aug 2004
Jacob,

>How do I detect whether my laptop is running on battery or using the
>power outlet?


Try the GetSystemPowerStatus Win32 API function:

http://msdn.microsoft.com/library/en...owerstatus.asp

You can probably also get this information with WMI
(System.Management).



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Imran Koradia
Guest
Posts: n/a
 
      12th Aug 2004
look at the Win32_PortableBattery class under WMI.
check the Availability, BatteryStatus and Status properties - those might be
what you're looking for.

hope this helps..
Imran.

"Jacob Thastrup.com" <Jacob@-RemoveMe-thastrup.com> wrote in message
news:(E-Mail Removed)...
> Hi
>
> How do I detect whether my laptop is running on battery or using the
> power outlet?
>
> Thanks
>
> Jacob Thastrup



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Aug 2004
* "Jacob Thastrup.com" <Jacob@-RemoveMe-thastrup.com> scripsit:
> How do I detect whether my laptop is running on battery or using the
> power outlet?


My FAQ:

Information about the system power status (battery status) can be obtained
using the 'GetSystemPowerStatus' platform function:

\\\
Imports System.IO
Imports System.Runtime.InteropServices
..
..
..
Private Declare Auto Function GetSystemPowerStatus Lib "kernel32.dll" ( _
ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS _
) As Boolean

<StructLayout(LayoutKind.Sequential)> _
Public Structure SYSTEM_POWER_STATUS
Public ACLineStatus As ACLineStatus
Public BatteryFlag As BatteryFlag
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Int32
Public BatteryFullLifeTime As Int32
End Structure

Public Enum ACLineStatus As Byte
Offline = 0
Online = 1
UnknownStatus = 255
End Enum

<Flags()> _
Public Enum BatteryFlag As Byte
High = 1
Low = 2
Critical = 4
Charging = 8
NoSystemBattery = 128
UnknownStatus = 255
End Enum
..
..
..
Dim sps As SYSTEM_POWER_STATUS
If GetSystemPowerStatus(sps) Then
Dim sw As New StringWriter()
With sps
sw.WriteLine("ACLineStatus: " & .ACLineStatus.ToString())
sw.WriteLine("BatteryFlag: " & .BatteryFlag.ToString())
sw.WriteLine( _
"BatteryLifePercent: " & _
IIf( _
.BatteryLifePercent = 255, _
"Unknown", _
.BatteryLifePercent.ToString() & " percent" _
) _
)
sw.WriteLine( _
"BatteryLifeTime: " & _
IIf( _
.BatteryLifeTime = -1, _
"Unknown", _
.BatteryLifeTime.ToString() & " seconds" _
) _
)
sw.WriteLine( _
"BatteryFullLifeTime: " & _
IIf( _
.BatteryFullLifeTime = -1, _
"Unknown", _
.BatteryFullLifeTime.ToString() & " seconds" _
) _
)
End With
MsgBox(sw.ToString())
Else

' An error occured.
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Aug 2004
Herfried,

I asssume this is no code directly written by you, IIF?

:-)

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
detect file status Tony WONG Microsoft VB .NET 14 13th May 2009 12:40 PM
detect file status Tony WONG Microsoft VB .NET 0 13th May 2009 08:08 AM
SP2 cannot detect NAV 2003 status? PhiL M. Windows XP General 8 20th Aug 2004 12:23 AM
Detect docking status =?Utf-8?B?QmlsbA==?= Windows XP General 2 17th Mar 2004 09:06 PM
IE detect status code RdU Microsoft VB .NET 0 9th Jul 2003 11:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.