Old 14th September 2009, 12:47   #1
webtubbies
Junior Member
 
Join Date: Sep 2009
Posts: 17
How to check power supply plugged?

Hello everybody,

I'm looking for a way to check if the power supply of a leptop is plugged when then user runs installer.

I'm not "fluent" in NSIS language, and at this time i've found nothing to help me.
webtubbies is offline   Reply With Quote
Old 14th September 2009, 13:07   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
You need to use the system plugin to call the API command GetSystemPowerStatus() in Kernel32.dll. See:
http://nsis.sourceforge.net/Docs/Sys...html#callfuncs
And:
http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
MSG is offline   Reply With Quote
Old 14th September 2009, 14:40   #3
webtubbies
Junior Member
 
Join Date: Sep 2009
Posts: 17
Thank You for links.
But i'm still lost... I don't understand the parameter I have to give to the Proc.
I'm so sorry.
webtubbies is offline   Reply With Quote
Old 14th September 2009, 19:51   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
code:
System::Alloc 12
Pop $1
System::Call "kernel32::GetSystemPowerStatus(i r1)"
System::Call "*$1(&i1 .r2, &i1 .r3, &i1 .r4, &i1, i .r5, i .r6)"
System::Free $1
MessageBox MB_OK "ACLineStatus=$2, BatteryFlag=$3, BatteryLifePercent=$4, \
BatteryLifeTime=$5, BatteryFullLifeTime=$6"


See for details on the possible values: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

If you want to know how this works, take a close look at the system plugin readme I linked to. It allocates memory for a SYSTEM_POWER_STATUS structure, then calls the GetSystemPowerStatus function. It then disassembles the structure into four 1-byte integers and two DWORDS (which are 4 bytes each). (Props to Anders for teaching me how to use these things.)
MSG is offline   Reply With Quote
Old 15th September 2009, 12:12   #5
webtubbies
Junior Member
 
Join Date: Sep 2009
Posts: 17
Hello MSG,

thank you for this snippet. I didn't understand that I have to allocate memory before the call.
Anyway, You right when you say I have to take a closer look to the msdn page.

(Sorry for my english I'm not fluent in this language too)
webtubbies is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump