Search code examples
pythonwindowsslideshowdesktoppowercfg

How to change desktop background settings slideshow through powercfg using Python?


I'm running Python 2.7.11 on Windows 10 and I need to automatically pause and resume the desktop background slideshow for a program.

My current approach is to issue commands to the command prompt thru Python's subprocess module. Below are the commands I've tried.

subprocess.call("powercfg -change -0d7dbae2-4294-402a-ba8e-26777e8488cd-309dce9b-bef4-4119-9921-a851fb12f0f4 1");

subprocess.call("powercfg -change -desktop-background-settings 1");

I know that the commands aren't working as I've tried issuing them directly thru command prompt and I've received "invalid parameters" as an error message.

Any instruction on how to achieve this thru powercfg or another method is appreciated. Thanks.


Solution

  • Ok so, after a bit of experimentation I've found the answer to my own question. First of all, the -change command can't be used on the desktop background settings setting. Reference

    To edit the value of any powercfg setting, I'd instead use -setacvalueindexor -setdcvalueindex. I found a helpful powercfg guide here.

    For posterity, here is the code that worked.

    subprocess.call("powercfg -setacvalueindex " + GUID + " 0d7dbae2-4294-402a-ba8e-26777e8488cd 309dce9b-bef4-4119-9921-a851fb12f0f4 1"); subprocess.call("powercfg -setdcvalueindex " + GUID + " 0d7dbae2-4294-402a-ba8e-26777e8488cd 309dce9b-bef4-4119-9921-a851fb12f0f4 1");

    Where the variable GUID is the GUID of the current Windows power plan. The above commands pause the slideshow on AC and DC power on the Balanced power plan. To start the slide show use the same command with the last character in the string as 0 instead of 1