Archive: How to check power supply plugged?


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.


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


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.


  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.)

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)