You might recall from last month's column ("Powercfg Gets Sleepy," InstantDoc ID 102240) that Powercfg lets you access helpful power-management features that you can't get from the GUI—but it's fairly complex, as is unfortunately the case for many command-line tools. One feature that I find handy is the ability to reconfigure a power scheme with Powercfg, but I've refrained from writing about it because the syntax can be pretty ugly. However, as I've spoken about Powercfg over the past few months, people often ask for more about the utility. They correctly point out that if you want to script a hands-off Windows setup but want to create custom power settings, Powercfg is the only game in town. So, this month, let's use Powercfg to configure Windows to inform us when our batteries are low.

Ugly but Powerful
As I showed you in "Powercfg" (InstantDoc ID 48399), Powercfg 's /x option is great for controlling four settings: when to dim the screen, how many minutes of inactivity to wait before going to standby and before going to sleep, and when to turn off the disk. But there are many other timeout/notification options—for example, at what percent of battery strength should Windows notify you, what percent constitutes "critical" battery levels, and should you enable adaptive display brightness. To set these options with Powerfcg, you use the -setacvalueindex and -setdcvalueindex options.

Here's an example. By default, Windows warns you of low battery life when your battery reaches 10 percent, but so many batteries seem to go from 10 percent to dead flat in about two minutes. You'd like to set that percentage to, say, 20 percent. Generically, the command looks like

 powercfg -setdcvalueindex (scheme GUID)
(sub-GUID identifying the family of settings we're about to modify)
(setting-GUID identifying the particular setting we're modifying)
(desired value for the setting)


That's a lot of items to specify, and figuring them out isn't obvious. So, let me just skip to the answer first, then show you how I derived it. Ready? Here it comes:

powercfg -setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e
e73a048d-bf27-4f12-9731-8b2076e8891f
8183ba9a-e910-48da-8769-14ae6dc1170a 20


Now you can see why I thought no one would ever want to try to figure this out. But after I pick apart this example, others will be easier. In this example, 381b4222-f694-41f0-9685-ff5bb260df2e is the GUID that instructs Powercfg to make this modification to the Balanced power scheme (rather than the High performance or Power saver scheme). Recall from "Powercfg Revisited" (InstantDoc ID 102005) that you can use the Powercfg -l command to list all the power schemes on your system, as well as their GUIDs. The two GUIDs e73a048d-bf27-4f12-9731-8b2076e8891f and 8183ba9a-e910-48da-8769-14ae6dc1170a are essentially informing the system that you want to modify a battery setting and that this setting specifies the percentage of remaining battery power that should trigger a "low power battery" event. Finally, 20 sets the low-battery-power threshold to 20 percent.

The Microsoft thinking here was apparently to build a hierarchy of objects (battery-setting value within an overall notion of battery monitoring and control, within a power scheme that contains lots of things besides battery information), give them GUIDs so that they're easy for a programmer to identify, and let Powercfg control them. So, to assemble one of these -setdcvalueindex or -setacvalueindex commands, you need to locate the power scheme's GUID (Powercfg -l), the sub GUID that refers to the general area of what you want to control (e73a048d-bf27-4f12-9731-8b2076e8891f—the sub-GUID for "battery," in this example), the GUID that refers to what, specifically, we're setting (8183ba9a-e910-48da-8769-14ae6dc1170a—the "low battery charge" setting, in this example), and finally whatever you want to set (20, in this case). By the way, the Powercfg documentation claims that you can feed the utility numeric values in hex with the 0x prefix, but I've never gotten it to work.

The only missing piece is, of course, where to find the sub-GUID and the setting GUID. The easiest place I've seen to get them is by using Powercfg -q to dump your current settings. When you do that, you'll receive a lot of output. But look for lines that refer to whatever you're trying to set, such as

 Power Setting GUID: 8183ba9a-e910-48da-8769-14ae6dc1170a (Low battery level)

Ah, now you see the GUID for the low battery setting. But where is the sub-GUID for the battery "group?" Scrolling further up from that line, you'll find

Subgroup GUID: e73a048d-bf27-4f12-9731-8b2076e8891f (Battery)

Get the Hang of It
Yes, assembling a -setdcvalueindex or -setacvalueindex command isn't easy, but sometimes it's your only option. Try this example on a laptop, and you'll be ready to put together a Powercfg command for any need!