Curtis,
This post explains the scripts-shortcuts to allow you to do what you want. The shortcuts use the Windows command PowerCfg so I start by explaining it in order to have less explanatory clutter in my explanations of the scripts-shortcuts themselves.
I will return later to explain how to automate the first of them [reaction to detecting an HDMI connection] but, as explained earlier on, I do not think the return action can be automated.
1 Intro: The built-in PowerCfg utility
You do not have to read this section but I think it will resolve doubts you might otherwise have when doing the job later on.
The solution uses the built-in Windows command PowerCfg [like all commands, it is actually in lowercase; I just type it that way because it helps me spot typos. Windows does not care either way.]
PowerCfg can be used to report power scheme properties and to change them.
PowerCfg’s full supporting documentation was last published a decade ago and is no longer even available to download. MS might well have altered details of the PowerCfg command for all any of us know. So I always adopt a cautious approach and double-check the effects of any command I use.
- You can see its built-in Help file still by using the command
PowerCfg /? in a cmd/PS window.
- You can also see the guidance in
PowerCfg - SS64
Powercfg - MSDocs
PowerCfg can report many power scheme properties by using its /q switch but only by using the undocumented /qh switch can you be sure of getting all the properties. Quite why MS decided to have some properties as h, as hidden, is beyond any mortal.
The command
PowerCfg /qh
reports all the properties. I often find it handy to save them to a file by ‘piping’ the output to a file. There are a lot and they will appear to be an unintelligible mess.
PowerCfg /qh > “D:\Desktop\ThisPowerSchemeProperties.txt”
or, added later,
PowerCfg /qh > “C:\Users\%UserName%\Desktop\ThisPowerSchemeProperties.txt”
- Naturally, your version of this will need to use a convenient folder that exists on your computer.
- I’ve enclosed the folder path & filename in quotation marks. Doing so does not do any harm if when they are not needed. They ensure that the command will work correctly even if you have spaces or special characters such as ampersands in the folder path or filename.
- When I do this, I then open it in Word & replace all the double-spacing of lines so there are no blank lines left [Replace ^p^p with ^p] and then I copy what’s left into Excel so I can use its excellent filtering capabilities when I’m hunting for something.
- Generally-speaking, PowerCfg commands to report things can be run in any Cmd/PS window whilst altering properties requires Admin permission. Since any PowerCfg job I do involves both checking things & altering things, I tend to just open an Admin Cmd/PS window for the whole lot.
You can also get PowerCfg to report specific sections from the properties so you can focus on specific topics. For example,
PowerCfg /qh SCHEME_BALANCED SUB_BUTTONS LIDACTION > “D:\Desktop\ThisPowerSchemeProperties-LidCloseAction.txt”
or, added later,
PowerCfg /qh SCHEME_BALANCED SUB_BUTTONS LIDACTION > “C:\Users\%UserName%\Desktop\ThisPowerSchemeProperties-LidCloseAction.txt”
will just report those properties within the
Lid close action section.
I always check the properties both before & after changing anything because I find it easy to make mistakes in the very long command syntax that is often necessary. I checked them repeatedly when working out the commands you need to use. And I’m checking them repeatedly while typing this so I know I’m copying across from my notes accurately.
2 Please test the assumptions I’ve made
2.1 I think the Lid open action property is irrelevant, that it is a redundant property
I spotted a property that seemed relevant but testing it on my computers showed that it was not. Please run this command to check your computer.
powercfg /qh SCHEME_BALANCED SUB_BUTTONS LIDOPENWAKE
I think you will get this response
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)
GUID Alias: SCHEME_BALANCED
Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347 (Power buttons and lid)
GUID Alias: SUB_BUTTONS
Power Setting GUID: 99ff10e7-23b1-4c07-a9d1-5c3206d741b4 (Lid open action)
GUID Alias: LIDOPENWAKE
Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Turn on the display
Current AC Power Setting Index: 0x00000001
Current DC Power Setting Index: 0x00000001
which indicates that the computer is already set to turn on the display when the lid is opened.
If yours also shows the value 1 for the two final lines then we can conclude that it is not relevant to the job.
The main reason I was concerned was that I could not think of any circumstances in which you’d want it to be set any other way so I could not understand why the property even existed.
2.2 I assumed that you only use the Balanced power plan
I only use the Balanced power plan but I do not know about you. If you have others that you want to script-shortcuts to apply to then I’ll only have to add additional lines to the scripts.
Please run this command
PowerCfg /l >”D:\desktop\PowerPlansList.txt”
or, added later,
PowerCfg /l >”C:\Users\%UserName%\Desktop\PowerPlansList.txt”
If you only get the response
Existing Power Schemes (* Active)
-----------------------------------
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *
then that’s fine. If you get more than that and if you want to use the script-shortcuts for them all, please post your response and I’ll add the bits needed.
You do not need to wait. Setting everything up can still be done using what I’ve written below and you can add the necessary additional bits later on. I’m keen not to leave you dangling without any progress being made as I’ve done for the past week.
2.3 I assumed that you do not want to change your display timeout
When I connect to my external display, I do not change my display timeout. I’ve connected it to do some work so I’ll be using the keyboard and mouse and the display will stay on anyway. If I stop to make a pot of tea then I’m happy for the display to go off as normal until I return.
When, however, I connect to my TV I always set the display to stay on forever. I’ll be watching a film or TV recording on it so won’t be using the keyboard or mouse and therefore the display would otherwise turn off partway through.
If you want to do this as weel then just let me know.
You do not need to wait. Setting everything up can still be done using what I’ve written below and you can add the necessary additional bits later on.
3 Create the script to tell your computer to do nothing when the lid closes.
3.1 Write the script itself
LidCloseAction-DoNothing.bat is attached anyway but I wanted to show you its content here as well.
powercfg /SetacValueIndex SCHEME_BALANCED SUB_BUTTONS LIDACTION 0
powercfg /SetdcValueIndex SCHEME_BALANCED SUB_BUTTONS LIDACTION 0
:: Pause to check during testing
If you would like to see any response while you are testing then you can temporarily remove the ∷ {colon colon space} so the window will stay open afterwards for you to have a look.
3.2 Store the script after testing
You can run the batch file to check that it works. You can run the command
powercfg /qh SCHEME_BALANCED SUB_BUTTONS LIDACTION
both before and after each test to check that the change has taken place. You can, of course, also check in
Power options,
Choose what closing the lid does. I just find it convenient to use the command window to do it.
When you are happy that the script works then you can put it in a permanent location. I put all my scripts within a [protected] C:\Tools folder that I have created for that purpose. See
Set up my Tools folder ditty - TenForums
3.3 Create a shortcut to the script
Create a shortcut in the normal way [right-click on the file, select
Create shortcut].
I always trim of the
.bat - Shortcut from a shortcut’s name because I don’t find it helpful. So
LidCloseAction-DoNothing.bat - Shortcut.lnk becomes
LidCloseAction-DoNothing.lnk assuming that you have set your File explorer to always show file extensions as I always do.
If you’ve put the script in a protected folder as I suggested above then Windows will say it cannot create it in the same place and will offer to create it on your Desktop instead. That will be fine.
Right-click on the shortcut and tell it to run minimised and set a particular icon if you want to. When you are happy with it, copy it back into the script’s folder [which will require Admin permission if you’ve protected the folder] and then you can move the shortcut to anywhere that’s convenient for you.
I will return to the uses of the shortcut later on when we discuss automating things.
4 Create the script to tell your computer to Sleep when the lid closes.
4.1 Write the script itself
LidCloseAction-Sleep.bat is attached anyway but I wanted to show you its content here as well.
powercfg /SetacValueIndex SCHEME_BALANCED SUB_BUTTONS LIDACTION 1
powercfg /SetdcValueIndex SCHEME_BALANCED SUB_BUTTONS LIDACTION 1
:: Pause to check during testing
If you would like to see any response while you are testing then you can temporarily remove the ∷ {colon colon space} so the window will stay open afterwards for you to have a look.
4.2 Store the script after testing
You can run the batch file to check that it works. You can run the command
powercfg /qh SCHEME_BALANCED SUB_BUTTONS LIDACTION
both before and after each test to check that the change has taken place. You can, of course, also check in
Power options,
Choose what closing the lid does. I just find it convenient to use the command window to do it.
When you are happy that the script works then you can put it in a permanent location. I put all my scripts within a [protected] C:\Tools folder that I have created for that purpose. See
Set up my Tools folder ditty - TenForums
Once you are happy that both scripts work you can test both scripts one after the other to see the property changing back & forth each time.
4.3 Create a shortcut to the script
Create a shortcut in the normal way [right-click on the file, select
Create shortcut].
I always trim of the
.bat - Shortcut from a shortcut’s name because I don’t find it helpful. So
LidCloseAction-Sleep.bat - Shortcut.lnk becomes
LidCloseAction-Sleep.lnk assuming that you have set your File explorer to always show file extensions as I always do.
If you’ve put the script in a protected folder as I suggested above then Windows will say it cannot create it in the same place and will offer to create it on your Desktop instead. That will be fine.
Right-click on the shortcut and tell it to run minimised and set a particular icon if you want to. When you are happy with it, copy it back into the script’s folder [which will require Admin permission if you’ve protected the folder] and then you can move the shortcut to anywhere that’s convenient for you.
I will return to the uses of the shortcut later on when we discuss automating things.
5 This is, I believe, a useful halfway house
You can now do what you want more conveniently than before.
Ask any questions you want.
I will return to the question of automating
LidCloseAction-DoNothing.bat so you can achieve what you set out to do. It’s a different topic and it involves use of both Event Viewer & Task Scheduler.
When this is all done, you might wish to automate the
LidCloseAction-Sleep.bat as well [if only for experimentation] but your recent post seems to match my own results so I don’t think it is a viable course of action. Those interim Events while the external display is connected mean that
LidCloseAction-Sleep.bat would run while you were still connected instead of only afterwards. But if you want to experiment then I’ll help you.
All the best,
Denis