Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   How to check power supply plugged? (http://forums.winamp.com/showthread.php?t=312359)

webtubbies 14th September 2009 12:47

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.

MSG 14th September 2009 13:07

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

webtubbies 14th September 2009 14:40

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.

MSG 14th September 2009 19:51

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

webtubbies 15th September 2009 12:12

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)


All times are GMT. The time now is 17:24.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.