How to prevent laptop screen brightness from changing when un/plugging battery power

When I am using my laptop, I continually adjust the screen's brightness based on the lighting conditions in the room (e.g. how much light is coming in from windows, etc.). But if I unplug the laptop or plug it back in, Windows looks at the default brightness setting in the power profile for "on battery" or "plugged in" and changes the brightness accordingly. This is a jarring experience and then I have to hunt down the ideal brightness for my current situation again, rather than getting on with my work.

I would like to make it so that plugging or unplugging the battery is not a trigger that adjusts the screen brightness at all. The screen brightness should only change when I adjust it myself. Does anybody know how this might be accomplished?

Edit: I have encountered this issue in both Windows Vista and Windows 7.


Ok, after few hours of brain excercies i have made this powershell script..here it is

while($true)
{

$a = Get-WmiObject -ns root/wmi -class wmiMonitorBrightNess
$a1 = $a.Currentbrightness

$b = Get-WmiObject -ns root/wmi -class batterystatus
$b1 = $b.poweronline

start-sleep 1

$b = Get-WmiObject -ns root/wmi -class batterystatus
$b2 = $b.poweronline

If ($b2 -ne $b1)
{
$c = Get-WmiObject -ns root/wmi -class wmiMonitorBrightNessMethods
$c.WmiSetBrightNess(0,$a1)
}

}

Copy in notepad and save with ".ps1" extension.

What it does is, it frequently checks for the power state plugged in or not. If power state is changed it will restore the previous brightness value.

I have tested this in my laptop with Win8.1, works fine.

  • You can adjust the responsiveness by modifying start-sleep value (currently it is 1 second)

  • To run this script Powershell execution policy must be changed from default.

  • This script is only theoretical example, in practice the powershell windows will remain open, may be problematic for some. I am not discussing the ways to hide the window.


I was getting mad with the same problem as Nomad's and DrNT007's solution worked great.

I searched a bit on the net in order to hide the powershell window and came to this thread and found user2656928's solution the best suiting for me: just add the following code at the top of DrNT007's script and the powershell window will momentarily show and then vanish:

$t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
add-type -name win -member $t -namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)

Then, I wanted to put the script in the windows startup folder but it gave me an error. I'm definitely a noob and solved this problem just by trial and error: I found out that the script name (and its path, i presume) must NOT contain spaces but, still, I can't understand why it gives error if directly put in the startup window... Anyway, i have put it in the windows folder and shortcutted it in the startup folder. This way, in Windows 8.1, works like a charm.