PC Review


Reply
Thread Tools Rate Thread

Detecting mains power

 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      22nd Sep 2004
Does anyone know of any way of detecting whether a device has mains
power or not? I can see power state changes, but can't tell from them
whether the device is connected to a decent power supply.

(We'd like our app to keep trying to download updates if it's on mains
power, but not otherwise.)

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
 
Neil Cowburn
Guest
Posts: n/a
 
      22nd Sep 2004
P/Invoke GetSystemPowerStateEx and check the value of the ACLineStatus of
the returned SYSTEM_POWER_STATUS_EX structure.

A value of 1 indicates that an AC supply is the power source. Zero indicates
battery is the power source.

Alternatively, check out GetSystemPowerStateEx in OpenNETCF.Win32.Core
(http://opennetcf.org/SourceBrowse/vi.../Win32/Core.cs
go to Line 1627)

HTH
Neil

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Does anyone know of any way of detecting whether a device has mains
> power or not? I can see power state changes, but can't tell from them
> whether the device is connected to a decent power supply.
>
> (We'd like our app to keep trying to download updates if it's on mains
> power, but not otherwise.)
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      22nd Sep 2004
Neil Cowburn <(E-Mail Removed)> wrote:
> P/Invoke GetSystemPowerStateEx and check the value of the ACLineStatus of
> the returned SYSTEM_POWER_STATUS_EX structure.
>
> A value of 1 indicates that an AC supply is the power source. Zero indicates
> battery is the power source.
>
> Alternatively, check out GetSystemPowerStateEx in OpenNETCF.Win32.Core
> (http://opennetcf.org/SourceBrowse/vi...NETCF/InetPub/
> wwwroot/Source/OpenNETCF/Win32/Core.cs
> go to Line 1627)


Aha - many thanks. Not sure why I didn't see that before. Even better,
I've just discovered the BatteryFlag enumeration too, so we can be even
more discriminating

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      22nd Sep 2004
You have to be conservative about using that. Not all devices have detailed
battery-left information available. Don't forget to handle the
BatteryUnknown case...

Paul T.

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Neil Cowburn <(E-Mail Removed)> wrote:
>> P/Invoke GetSystemPowerStateEx and check the value of the ACLineStatus of
>> the returned SYSTEM_POWER_STATUS_EX structure.
>>
>> A value of 1 indicates that an AC supply is the power source. Zero
>> indicates
>> battery is the power source.
>>
>> Alternatively, check out GetSystemPowerStateEx in OpenNETCF.Win32.Core
>> (http://opennetcf.org/SourceBrowse/vi...NETCF/InetPub/
>> wwwroot/Source/OpenNETCF/Win32/Core.cs
>> go to Line 1627)

>
> Aha - many thanks. Not sure why I didn't see that before. Even better,
> I've just discovered the BatteryFlag enumeration too, so we can be even
> more discriminating
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
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
should i use battery or mains power? kendrz Windows Vista General Discussion 6 24th Nov 2007 04:14 AM
Mains Power Fluctuation Question Taffycat General 5 14th Feb 2007 03:25 PM
Re: Typical mains power for mid-range PC? Jon D Computer Hardware 290 5th Aug 2006 09:29 PM
Typical mains power for mid-range PC? Jon D Computer Hardware 52 1st Aug 2006 02:18 PM
Low batter warning on desktop on mains power Tracey Carrington Microsoft Windows 2000 Hardware 0 4th May 2004 08:33 AM


Features
 

Advertising
 

Newsgroups
 


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