• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » How To? » Automatically Switch Windows Theme When on Laptop Battery

Automatically Switch Windows Theme When on Laptop Battery

Posted on May 28, 2012 by Renji | Short URL: http://sumtips.com/?p=6736

By tweaking Windows power plan settings, you can get the maximum performance out of your laptop battery. Unfortunately, there’s no setting in the power plan that will automatically switch themes on unplugging from the power source. Since Windows Aero skin is one of the biggest power hogger, this is like a must have setting in there, especially while you are travelling and there’s no way to re-charge anytime soon. In such situations what you want is more running time than the pretty look. Don’t fret though, you can get this functionality, in a geeky way.

By running a PowerShell script, you can constantly monitor your laptop battery state and switch themes when it changes. This is the script:

$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
while ($true)
{
	start-sleep -s 5
	if (((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -eq (1 -or 3 -or 4 -or 5 -or 10 -or 11)) -and ((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -ne $sav))
	{
		& 'C:\Windows\Resources\Ease of Access Themes\Classic.theme'
		$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
		}
	else
	{
		if ((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -ne $sav)
		{
			& 'C:\Windows\Resources\Themes\Aero.theme'
			$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
		}
	}
}

Copy-paste script to a text editor and it as a .PS1 file.

Above script is set to work with the default Windows 7 Aero and Classic themes. To use different themes, you just have to edit these two paths with the theme of your choice:

  • Unplug theme: C:\Windows\Resources\Ease of Access Themes\Classic.theme
  • Plugged in theme: C:\Windows\Resources\Themes\Aero.theme

Now run the script by right clicking on it and select Run with PowerShell. A blank command window should open up.

If it is the first time you are running a PowerShell script on your computer, you might get an error with a message like this:

The execution of scripts is disabled on this system. Please see “Get-Help about_signing” for more details.

It’s the “execution policy” security setting built into Windows PowerShell that’s blocking the script. The default execution policy is set to Restricted that means that scripts – including those you write yourself – won’t run.

To view your current execution policy setting, open up PowerShell command prompt, type in below command, and then press ENTER:

Get-ExecutionPolicy

To resolve this issue and run the script, you need to change the setting from Restricted to RemoteSigned. To do this, open PowerShell as administrator and type in:

Set-ExecutionPolicy RemoteSigned

Windows PowerShell

Now you can run self-made scripts and the one’s that are downloaded from the internet.

Try running the .PS1 script again. You will see a blank command window with a blinking cursor. It’s actively monitoring your laptop’s power state.

To run the script silently, that is without the command window popup, create a new VBScript with the following code:

Dim shell,command
command = "powershell.exe -nologo -command C:\path-to\script.ps1"
Set shell = CreateObject("WScript.Shell")
shell.Run command,0

Enter full path to your .PS1 file in line 2, and save this script as a .VBS file. This VBS frame will run the PowerShell script silently in the background without displaying a command window.

That’s all!

You can run the VBScript manually when needed, or add it to your Startup folder to automatically launch on Windows logon. Alternatively, you can set the execution as a scheduled task in the Task Scheduler as well.


Tweet

Related posts:

  • WordPress Theme Finder
  • Official Windows 7 Thanksgiving Theme
  • Official Windows 7 Ireland Theme
  • New Year In Japan Windows 7 Theme
  • Official Holiday Lights Theme for Windows 7
Categories: How To?, Tips 'n Tricks | Tags: Tips 'n Tricks, Windows 7
Adding Hotkey Navigation Feature on WordPress Posts
Snap a Window to Top or Bottom of the Screen

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Firesheep lets Anyone Hack into a Facebook or Twitter Account
    • Official Social Sharing Buttons on Blogger
    • Replace Picasa, Google+ Photos Without Losing Comments
    • Add Any Application to the Windows Desktop Context Menu
    • View Tweets as Snowflakes on Tweetflakes
    • Change or Disable Drag Threshold to Close Windows 8 Metro Apps
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy