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