Is there a way to automatically quit two programs when battery is below certain level?

Here is a script that will close 2 processes after you've dropped below 50% battery.

SetTimer, CheckBatteryLevel, 2000
Return

CheckBatteryLevel:

    VarSetCapacity(powerstatus, 1+1+1+1+4+4)
    success := DllCall("kernel32.dll\GetSystemPowerStatus", "uint", &powerstatus)
    batteryLifePercent := ReadInteger(&powerstatus,2,1,false)

    if (batteryLifePercent < 50)
    {
        KillIfExists("Rainmeter.exe")
        KillIfExists("MSI.exe")
    }
    Return

KillIfExists(p)
{    
    Process, Exist, % p
    If (ErrorLevel)
        Process, Close, % p
}

ReadInteger( p_address, p_offset, p_size, p_hex=true )
{
    value = 0
    old_FormatInteger := a_FormatInteger
    if ( p_hex )
    SetFormat, integer, hex
    else
    SetFormat, integer, dec
    loop, %p_size%
    value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) )
    SetFormat, integer, %old_FormatInteger%
    return, value
} 

I modified the code found in this post


Check this one out. http://batterysaver.codeplex.com/
Gives you the ability to kill processes based on a battery decrease.
The program is in early stages of development and isn't very user friendly, however it can still get the job done and kudos to Ryan Emerly for his hard work on deveolopment. You will have to run the program as administrator and play around with it a bit to get it working.

Source: Is there a way to execute a program on power events?