Automatic Power Plan switch when HDMI is plugged in. Please help!


Local time
12:40 PM
Posts
15
OS
Windows 11
Hello,

I will be purchasing a HDMI monitor for my Laptop. I want to be able to close the laptop as I work with the monitor, the problem I find is that it's incredibly annoying having to manually change the power plan settings each time I want to use my laptop, or my monitor.

Is there anyway I can automatically change the power plan (don't sleep when lid is closed) when a HDMI cable is detected, and to revert back once the cable is removed?

I have seen maybe one or two people ask this on the internet, and not a lot of discussion around this.

Thanks

Curtis

Laptop:
Huawei Matebook Pro
16gb RAM
 
Windows Build/Version
Windows 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

glasskuter

Well-known member
Power User
VIP
Local time
6:40 AM
Posts
1,592
Location
The Lone Star State of Texas
OS
Windows 11 Pro 21H2 22000.675
Sorry Curtis, I do not think there is a way to make the laptop automatically change power option setting by setting a condition such as the presence of an hdmi cable. However, I believe this could be controlled by using 2 vbs script files, one for lid action closed= sleep and one for lid action closed = Do Nothing. Clicking a shortcut to each script file would be much easier than having to go to power options and manually changing your "close the lid action" each time. I am going to tag Denis @Try3 to see if he can accomplish this for you. He's proficient in using scripts.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 21H2 22000.675
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 7080
    CPU
    i9-10900
    Memory
    32 gb
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 m.2 2230-256+1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell Premium
    Keyboard
    Logitech wired
    Mouse
    Logitech wireless
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium
  • Operating System
    Windows 10 Pro 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 9020
    CPU
    i7-4770
    Memory
    24 gb
    Screen Resolution
    2560x1440
    Hard Drives
    256 gb Toshiba BG4 M.2 NVE SSB and 1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    standard
    Mouse
    Logitech wireless
    Keyboard
    Logitech wired
    Antivirus
    Defender+MWB Premium

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Sorry Curtis, I do not think there is a way to make the laptop automatically change power option setting by setting a condition such as the presence of an hdmi cable. However, I believe this could be controlled by using 2 vbs script files, one for lid action closed= sleep and one for lid action closed = Do Nothing. Clicking a shortcut to each script file would be much easier than having to go to power options and manually changing your "close the lid action" each time. I am going to tag Denis @Try3 to see if he can accomplish this for you. He's proficient in using scripts.
Thank you for the response. I read something about Event Viewer? Honestly, I'm very much a video editing graphics guy, I know nothing about scripts etc.

Thanks
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
Curtis,

If you do what you want using Power options at first to prove that it can be done with your external monitor connected then I can work out a script to semi-automate it i.e to carry out the changes when you run a shortcut to the script.
- Prove that it responds as expected to don't sleep when lid is closed
- Prove that it responds as expected to sleep when lid is closed

I have never looked into events upon connection of a monitor and have no idea if there is anything I could latch onto to make it fully automatic.
- I'll have a look around Windows 10 and would be able to guide you through Event viewer to see if anything I find also applies to Windows 11.
- But, as I say, I don't know that there is a useful event to latch onto.

Please post the results of this command as well so I know what power states are available.
PowerCfg -a
- You can run it in any cmd or PowerShell window
- If you were using Windows 10, you would see a link to a PowerShell window when you right-clicked on the Start button but I don't know about Windows 11 because I've jobbed my system to disable the Start button [Well, it was a side effect. I jobbed it to allow me to carry on using Taskbar Toolbars].
- Right-click on Start and select Windows Terminal then run the command in there.
- Select all the text in the window and copy it then paste it in here. After posting, check it is shown correctly and has not lost its line returns. If it has you should be able to edit the post and it will then obey the returns you put in.

Just out of interest, I looked for a Huawei Matebook Pro but what I found was a HUAWEI MateBook X Pro Is that the same thing?

All the best,
Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
Curtis,

I have good news & bad news.
- The good news is that there might be a solution that can be automated.
- The bad news is that I'll need you to do some more work to see if your results match mine.

Please don't be put off by being asked to use parts of Windows you might not be familiar with. Just take it one sentence at a time and post back with any questions you might have [and with answers to the questions I'm asking].

What I've discovered [On one Windows 10 computer only]
- I have identified an "Event" related to display settings that occurs when switching to an external display. That could be used to trigger a script to disable the sleep on lid closing action. Provided that your computer also records this Event, this part of the process could be automated.
- I have identified an "Event" related to display audio that occurs when switching back from an external display that has speakers. That could be used to trigger a script to re-enable the sleep on lid closing action. There is one awkward thing about the Event that might stop us from being able to use it sensibly and it will take experimentation to find out. If it proves to be practicable then the whole disabling/re-enabling sleep on lid closing could be automated but, if not, I'd have to give you a separate script that you'd have to initiate manually.
Question - Does your external monitor have speakers?

What I'd like you to do
- Import this "Event viewer, Custom view" to monitor the EventIDs I have found.
- I've attached the [zipped] definition for that Event viewer, Custom view - Display switching.zip
1 Unzip the file and it will reveal Display switching.xml, the Custom view definition.
Before importing it, you can read the unzipped xml file in Notepad or, for a better presentation of its contents, by right-clicking and opening in a browser.
2 Open Event viewer, click on Import Custom view [on the right-hand side],
3 Browse to and select the xml, Open,
4 Change the name if you want to [I call it Display switching but you can call it whatever you want] then OK,
5 You can see the records, on the left-hand side, within the group Custom views.

What you'll see in the Custom view
Display switching.png
Note 1 - At 12:35, 12:50, I connected & immediately displayed the external monitor on my desk. It has always been set as to "Extended display" view so it switches to that as soon as it is connected & the monitor is turned on. If it does the same on your computer, the EventID 112 DeviceSetupManager can be used to trigger your upon-connection script.
Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?
Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Note 2 - At 12:37, 12:54, I turned off & disconnected the external display so the computer returned to displaying on the computer only. If it does the same on your computer, the EventID 65 Audio can be used to trigger your upon-disconnection script. I think I can work out how to ignore the initial audio Event that happens at the same time as connecting to the monitor.
Note 3 - At 13:02, I connected my TV. EventID 112 DeviceSetupManager worked as before. I was clumsy in doing this as it was off and you'll see that there were several audio Events. I had to turn it on, switch it to external input, wake up the screen because I'd been so slow that my computer's monitor had turned off. I think those 13:02:57, 13:03:57 Events match those interim stages, in which case they ought to be manageable in your case because you won't be using an external monitor twelve feet away. My TV has always been set as to "Second screen-only display" view so it switches to that as soon as it is connected
Question - Will there be any awkwardness in your external monitor use or will you just connect its HDMI and turn it on as I was able to do for the external monitor on my desk?
Note 4 - At 13:04, I turned off & disconnected the TV. EventID 65 Audio worked as before.

Further tests
- Please don't forget to check that, with your new monitor, you can successfully change the lid close action using Power options. Some computers have the action hard-wired into the Bios so they cannot be changed.
Question - Have you tested that yet?
- Please don't forget to run PowerCfg -a
Question - Have you run PowerCfg -a yet?
- I do have one further Event to test out that I might be able to use in conjunction with the ones I've already identified. It might help with clumsy connections/switching like I had with my TV. No joy. I searched for a lid close Event but there isn't one so the refinement I was considering is not possible.


All the best,
Denis
 

Attachments

  • Display switching.zip
    473 bytes · Views: 2
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Curtis,

If you do what you want using Power options at first to prove that it can be done with your external monitor connected then I can work out a script to semi-automate it i.e to carry out the changes when you run a shortcut to the script.
- Prove that it responds as expected to don't sleep when lid is closed
- Prove that it responds as expected to sleep when lid is closed

I have never looked into events upon connection of a monitor and have no idea if there is anything I could latch onto to make it fully automatic.
- I'll have a look around Windows 10 and would be able to guide you through Event viewer to see if anything I find also applies to Windows 11.
- But, as I say, I don't know that there is a useful event to latch onto.

Please post the results of this command as well so I know what power states are available.
PowerCfg -a
- You can run it in any cmd or PowerShell window
- If you were using Windows 10, you would see a link to a PowerShell window when you right-clicked on the Start button but I don't know about Windows 11 because I've jobbed my system to disable the Start button [Well, it was a side effect. I jobbed it to allow me to carry on using Taskbar Toolbars].
- Right-click on Start and select Windows Terminal then run the command in there.
- Select all the text in the window and copy it then paste it in here. After posting, check it is shown correctly and has not lost its line returns. If it has you should be able to edit the post and it will then obey the returns you put in.

Just out of interest, I looked for a Huawei Matebook Pro but what I found was a HUAWEI MateBook X Pro Is that the same thing?

All the best,
Denis
Hi Denis,

This is what I got from putting in the first cmd line.

I will now go through your second post and follow the steps.

Thanks

Curtis
 

Attachments

  • powershell.jpg
    powershell.jpg
    116.1 KB · Views: 1

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Hi Denis,

This is what I got from putting in the first cmd line.

I will now go through your second post and follow the steps.

Thanks

Curtis
Here it is in text form:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! Migrating from Windows PowerShell 5.1 to PowerShell 7 - PowerShell

PS C:\Users\Curtis> PowerCfg -a
The following sleep states are available on this system:
Standby (S3)
Hibernate
Hybrid Sleep
Fast Startup

The following sleep states are not available on this system:
Standby (S1)
The system firmware does not support this standby state.

Standby (S2)
The system firmware does not support this standby state.

Standby (S0 Low Power Idle)
The system firmware does not support this standby state.

PS C:\Users\Curtis>
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
This is what I got from putting in the first cmd line.
Curtis,

Good. No reason to expect any complications then.
I'm surprised you have enabled Fast start & Hybrid sleep but that's up to you.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Curtis,

Good. No reason to expect any complications then.
I'm surprised you have enabled Fast start & Hybrid sleep but that's up to you.

Denis
I think they were the default, what's the pros of turning them off?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
Personally, I dislike Fast start because it inhibits the ability to use the Bios keys during start-up from shutdown. There's some discussion in
Turn On or Off Fast Start - ElevenForumTutorials
Fast boot, is it a good thing or bad - TenForums
The Pros and Cons of Windows 10s Fast Start - HTG
What is Fast Startup doing [f14tomcat] - TenForums

Hybrid sleep [which is normal sleep plus the hibernation file as a backup in case of power loss] just takes longer to get into because writing the hibernation file takes time. I like being able to sleep the computer in one second or thereabouts. There's a discussion in
Hybrid sleep - The Old New Thing - DevBlogs

All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Curtis,

I have good news & bad news.
- The good news is that there might be a solution that can be automated.
- The bad news is that I'll need you to do some more work to see if your results match mine.

Please don't be put off by being asked to use parts of Windows you might not be familiar with. Just take it one sentence at a time and post back with any questions you might have [and with answers to the questions I'm asking].

What I've discovered [On one Windows 10 computer only]
- I have identified an "Event" related to display settings that occurs when switching to an external display. That could be used to trigger a script to disable the sleep on lid closing action. Provided that your computer also records this Event, this part of the process could be automated.
- I have identified an "Event" related to display audio that occurs when switching back from an external display that has speakers. That could be used to trigger a script to re-enable the sleep on lid closing action. There is one awkward thing about the Event that might stop us from being able to use it sensibly and it will take experimentation to find out. If it proves to be practicable then the whole disabling/re-enabling sleep on lid closing could be automated but, if not, I'd have to give you a separate script that you'd have to initiate manually.
Question - Does your external monitor have speakers?

What I'd like you to do
- Import this "Event viewer, Custom view" to monitor the EventIDs I have found.
- I've attached the [zipped] definition for that Event viewer, Custom view - Display switching.zip
1 Unzip the file and it will reveal Display switching.xml, the Custom view definition.
Before importing it, you can read the unzipped xml file in Notepad or, for a better presentation of its contents, by right-clicking and opening in a browser.
2 Open Event viewer, click on Import Custom view [on the right-hand side],
3 Browse to and select the xml, Open,
4 Change the name if you want to [I call it Display switching but you can call it whatever you want] then OK,
5 You can see the records, on the left-hand side, within the group Custom views.

What you'll see in the Custom view
View attachment 24563
Note 1 - At 12:35, 12:50, I connected & immediately displayed the external monitor on my desk. It has always been set as to "Extended display" view so it switches to that as soon as it is connected & the monitor is turned on. If it does the same on your computer, the EventID 112 DeviceSetupManager can be used to trigger your upon-connection script.
Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?
Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Note 2 - At 12:37, 12:54, I turned off & disconnected the external display so the computer returned to displaying on the computer only. If it does the same on your computer, the EventID 65 Audio can be used to trigger your upon-disconnection script. I think I can work out how to ignore the initial audio Event that happens at the same time as connecting to the monitor.
Note 3 - At 13:02, I connected my TV. EventID 112 DeviceSetupManager worked as before. I was clumsy in doing this as it was off and you'll see that there were several audio Events. I had to turn it on, switch it to external input, wake up the screen because I'd been so slow that my computer's monitor had turned off. I think those 13:02:57, 13:03:57 Events match those interim stages, in which case they ought to be manageable in your case because you won't be using an external monitor twelve feet away. My TV has always been set as to "Second screen-only display" view so it switches to that as soon as it is connected
Question - Will there be any awkwardness in your external monitor use or will you just connect its HDMI and turn it on as I was able to do for the external monitor on my desk?
Note 4 - At 13:04, I turned off & disconnected the TV. EventID 65 Audio worked as before.

Further tests
- Please don't forget to check that, with your new monitor, you can successfully change the lid close action using Power options. Some computers have the action hard-wired into the Bios so they cannot be changed.
Question - Have you tested that yet?
- Please don't forget to run PowerCfg -a
Question - Have you run PowerCfg -a yet?
- I do have one further Event to test out that I might be able to use in conjunction with the ones I've already identified. It might help with clumsy connections/switching like I had with my TV. No joy. I searched for a lid close Event but there isn't one so the refinement I was considering is not possible.


All the best,
Denis
Hello,

I have imported the script into Event Viewer. I have no purchased the desired monitor yet so I will use my TV for now.

I'm not sure if this will make a difference, but my laptop doesnt have a HDMI slot, but the laptop comes with a USB adapter with a HDMI slot on it. I will then run a cable directly into the TV.

Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?

Extended display is when the monitor acts as a second screen at the same time as my laptop screen. Second screen only is when my laptop screen turns off and only shows on the monitor (desired effect)?

Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Didn't know that!
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Curtis,

I have good news & bad news.
- The good news is that there might be a solution that can be automated.
- The bad news is that I'll need you to do some more work to see if your results match mine.

Please don't be put off by being asked to use parts of Windows you might not be familiar with. Just take it one sentence at a time and post back with any questions you might have [and with answers to the questions I'm asking].

What I've discovered [On one Windows 10 computer only]
- I have identified an "Event" related to display settings that occurs when switching to an external display. That could be used to trigger a script to disable the sleep on lid closing action. Provided that your computer also records this Event, this part of the process could be automated.
- I have identified an "Event" related to display audio that occurs when switching back from an external display that has speakers. That could be used to trigger a script to re-enable the sleep on lid closing action. There is one awkward thing about the Event that might stop us from being able to use it sensibly and it will take experimentation to find out. If it proves to be practicable then the whole disabling/re-enabling sleep on lid closing could be automated but, if not, I'd have to give you a separate script that you'd have to initiate manually.
Question - Does your external monitor have speakers?

What I'd like you to do
- Import this "Event viewer, Custom view" to monitor the EventIDs I have found.
- I've attached the [zipped] definition for that Event viewer, Custom view - Display switching.zip
1 Unzip the file and it will reveal Display switching.xml, the Custom view definition.
Before importing it, you can read the unzipped xml file in Notepad or, for a better presentation of its contents, by right-clicking and opening in a browser.
2 Open Event viewer, click on Import Custom view [on the right-hand side],
3 Browse to and select the xml, Open,
4 Change the name if you want to [I call it Display switching but you can call it whatever you want] then OK,
5 You can see the records, on the left-hand side, within the group Custom views.

What you'll see in the Custom view
View attachment 24563
Note 1 - At 12:35, 12:50, I connected & immediately displayed the external monitor on my desk. It has always been set as to "Extended display" view so it switches to that as soon as it is connected & the monitor is turned on. If it does the same on your computer, the EventID 112 DeviceSetupManager can be used to trigger your upon-connection script.
Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?
Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Note 2 - At 12:37, 12:54, I turned off & disconnected the external display so the computer returned to displaying on the computer only. If it does the same on your computer, the EventID 65 Audio can be used to trigger your upon-disconnection script. I think I can work out how to ignore the initial audio Event that happens at the same time as connecting to the monitor.
Note 3 - At 13:02, I connected my TV. EventID 112 DeviceSetupManager worked as before. I was clumsy in doing this as it was off and you'll see that there were several audio Events. I had to turn it on, switch it to external input, wake up the screen because I'd been so slow that my computer's monitor had turned off. I think those 13:02:57, 13:03:57 Events match those interim stages, in which case they ought to be manageable in your case because you won't be using an external monitor twelve feet away. My TV has always been set as to "Second screen-only display" view so it switches to that as soon as it is connected
Question - Will there be any awkwardness in your external monitor use or will you just connect its HDMI and turn it on as I was able to do for the external monitor on my desk?
Note 4 - At 13:04, I turned off & disconnected the TV. EventID 65 Audio worked as before.

Further tests
- Please don't forget to check that, with your new monitor, you can successfully change the lid close action using Power options. Some computers have the action hard-wired into the Bios so they cannot be changed.
Question - Have you tested that yet?
- Please don't forget to run PowerCfg -a
Question - Have you run PowerCfg -a yet?
- I do have one further Event to test out that I might be able to use in conjunction with the ones I've already identified. It might help with clumsy connections/switching like I had with my TV. No joy. I searched for a lid close Event but there isn't one so the refinement I was considering is not possible.


All the best,
Denis
Ok so I have tested it and it doesnt seem to work.

I can manually change the settings for the laptop to do nothing when closed. I trid this with the TV and when I close the laptop, the display turns off and the main display shows on the TV but doesnt sleep, so my laptop is capable of doing it.

As I said before I'm not sure if the USB adapter to HDMI is affecting it.

Thanks

Curtis
 

Attachments

  • IMG_20220321_112800_resized_20220321_113019442[3046].jpg
    IMG_20220321_112800_resized_20220321_113019442[3046].jpg
    370.1 KB · Views: 0

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Curtis,

I have good news & bad news.
- The good news is that there might be a solution that can be automated.
- The bad news is that I'll need you to do some more work to see if your results match mine.

Please don't be put off by being asked to use parts of Windows you might not be familiar with. Just take it one sentence at a time and post back with any questions you might have [and with answers to the questions I'm asking].

What I've discovered [On one Windows 10 computer only]
- I have identified an "Event" related to display settings that occurs when switching to an external display. That could be used to trigger a script to disable the sleep on lid closing action. Provided that your computer also records this Event, this part of the process could be automated.
- I have identified an "Event" related to display audio that occurs when switching back from an external display that has speakers. That could be used to trigger a script to re-enable the sleep on lid closing action. There is one awkward thing about the Event that might stop us from being able to use it sensibly and it will take experimentation to find out. If it proves to be practicable then the whole disabling/re-enabling sleep on lid closing could be automated but, if not, I'd have to give you a separate script that you'd have to initiate manually.
Question - Does your external monitor have speakers?

What I'd like you to do
- Import this "Event viewer, Custom view" to monitor the EventIDs I have found.
- I've attached the [zipped] definition for that Event viewer, Custom view - Display switching.zip
1 Unzip the file and it will reveal Display switching.xml, the Custom view definition.
Before importing it, you can read the unzipped xml file in Notepad or, for a better presentation of its contents, by right-clicking and opening in a browser.
2 Open Event viewer, click on Import Custom view [on the right-hand side],
3 Browse to and select the xml, Open,
4 Change the name if you want to [I call it Display switching but you can call it whatever you want] then OK,
5 You can see the records, on the left-hand side, within the group Custom views.

What you'll see in the Custom view
View attachment 24563
Note 1 - At 12:35, 12:50, I connected & immediately displayed the external monitor on my desk. It has always been set as to "Extended display" view so it switches to that as soon as it is connected & the monitor is turned on. If it does the same on your computer, the EventID 112 DeviceSetupManager can be used to trigger your upon-connection script.
Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?
Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Note 2 - At 12:37, 12:54, I turned off & disconnected the external display so the computer returned to displaying on the computer only. If it does the same on your computer, the EventID 65 Audio can be used to trigger your upon-disconnection script. I think I can work out how to ignore the initial audio Event that happens at the same time as connecting to the monitor.
Note 3 - At 13:02, I connected my TV. EventID 112 DeviceSetupManager worked as before. I was clumsy in doing this as it was off and you'll see that there were several audio Events. I had to turn it on, switch it to external input, wake up the screen because I'd been so slow that my computer's monitor had turned off. I think those 13:02:57, 13:03:57 Events match those interim stages, in which case they ought to be manageable in your case because you won't be using an external monitor twelve feet away. My TV has always been set as to "Second screen-only display" view so it switches to that as soon as it is connected
Question - Will there be any awkwardness in your external monitor use or will you just connect its HDMI and turn it on as I was able to do for the external monitor on my desk?
Note 4 - At 13:04, I turned off & disconnected the TV. EventID 65 Audio worked as before.

Further tests
- Please don't forget to check that, with your new monitor, you can successfully change the lid close action using Power options. Some computers have the action hard-wired into the Bios so they cannot be changed.
Question - Have you tested that yet?
- Please don't forget to run PowerCfg -a
Question - Have you run PowerCfg -a yet?
- I do have one further Event to test out that I might be able to use in conjunction with the ones I've already identified. It might help with clumsy connections/switching like I had with my TV. No joy. I searched for a lid close Event but there isn't one so the refinement I was considering is not possible.


All the best,
Denis
Here is the log from the Event Viewer
Curtis,

I have good news & bad news.
- The good news is that there might be a solution that can be automated.
- The bad news is that I'll need you to do some more work to see if your results match mine.

Please don't be put off by being asked to use parts of Windows you might not be familiar with. Just take it one sentence at a time and post back with any questions you might have [and with answers to the questions I'm asking].

What I've discovered [On one Windows 10 computer only]
- I have identified an "Event" related to display settings that occurs when switching to an external display. That could be used to trigger a script to disable the sleep on lid closing action. Provided that your computer also records this Event, this part of the process could be automated.
- I have identified an "Event" related to display audio that occurs when switching back from an external display that has speakers. That could be used to trigger a script to re-enable the sleep on lid closing action. There is one awkward thing about the Event that might stop us from being able to use it sensibly and it will take experimentation to find out. If it proves to be practicable then the whole disabling/re-enabling sleep on lid closing could be automated but, if not, I'd have to give you a separate script that you'd have to initiate manually.
Question - Does your external monitor have speakers?

What I'd like you to do
- Import this "Event viewer, Custom view" to monitor the EventIDs I have found.
- I've attached the [zipped] definition for that Event viewer, Custom view - Display switching.zip
1 Unzip the file and it will reveal Display switching.xml, the Custom view definition.
Before importing it, you can read the unzipped xml file in Notepad or, for a better presentation of its contents, by right-clicking and opening in a browser.
2 Open Event viewer, click on Import Custom view [on the right-hand side],
3 Browse to and select the xml, Open,
4 Change the name if you want to [I call it Display switching but you can call it whatever you want] then OK,
5 You can see the records, on the left-hand side, within the group Custom views.

What you'll see in the Custom view
View attachment 24563
Note 1 - At 12:35, 12:50, I connected & immediately displayed the external monitor on my desk. It has always been set as to "Extended display" view so it switches to that as soon as it is connected & the monitor is turned on. If it does the same on your computer, the EventID 112 DeviceSetupManager can be used to trigger your upon-connection script.
Question - Do you know what I'm talking about with "Extended display", "Second-screen only" [below] & the other choices that appear when you press the WinKey-P keyboard combination?
Question - Do you know that you can set up shortcuts to switch between displays? It's a separate topic & it's very easy.
Note 2 - At 12:37, 12:54, I turned off & disconnected the external display so the computer returned to displaying on the computer only. If it does the same on your computer, the EventID 65 Audio can be used to trigger your upon-disconnection script. I think I can work out how to ignore the initial audio Event that happens at the same time as connecting to the monitor.
Note 3 - At 13:02, I connected my TV. EventID 112 DeviceSetupManager worked as before. I was clumsy in doing this as it was off and you'll see that there were several audio Events. I had to turn it on, switch it to external input, wake up the screen because I'd been so slow that my computer's monitor had turned off. I think those 13:02:57, 13:03:57 Events match those interim stages, in which case they ought to be manageable in your case because you won't be using an external monitor twelve feet away. My TV has always been set as to "Second screen-only display" view so it switches to that as soon as it is connected
Question - Will there be any awkwardness in your external monitor use or will you just connect its HDMI and turn it on as I was able to do for the external monitor on my desk?
Note 4 - At 13:04, I turned off & disconnected the TV. EventID 65 Audio worked as before.

Further tests
- Please don't forget to check that, with your new monitor, you can successfully change the lid close action using Power options. Some computers have the action hard-wired into the Bios so they cannot be changed.
Question - Have you tested that yet?
- Please don't forget to run PowerCfg -a
Question - Have you run PowerCfg -a yet?
- I do have one further Event to test out that I might be able to use in conjunction with the ones I've already identified. It might help with clumsy connections/switching like I had with my TV. No joy. I searched for a lid close Event but there isn't one so the refinement I was considering is not possible.


All the best,
Denis
Here is the log from the Event Viewer
 

Attachments

  • eventviewer.fw.png
    eventviewer.fw.png
    157.4 KB · Views: 1

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
Ok so I have tested it and it doesnt seem to work.
Which "it" doesn't work?

Here is the log from the Event Viewer
It looks as though you are seeing the same as I'm seeing but with more interim audio events.
Do the Event 112 entries coincide with connecting up to your TV?
If so then your don't sleep when lid is closed could be set up to run from that.

I don't think that the return to sleep when lid is closed can be done automatically because of those interim events. You'd have to keep a shortcut to the script and run it manually when you disconnect from the TV.

Question - Why do you ever want sleep when lid is closed set up? In other words, why not just have it always set to don't sleep when lid is closed?

Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
Which "it" doesn't work?


It looks as though you are seeing the same as I'm seeing but with more interim audio events.
Do the Event 112 entries coincide with connecting up to your TV?
If so then your don't sleep when lid is closed could be set up to run from that.

I don't think that the return to sleep when lid is closed can be done automatically because of those interim events. You'd have to keep a shortcut to the script and run it manually when you disconnect from the TV.

Question - Why do you ever want sleep when lid is closed set up? In other words, why not just have it always set to don't sleep when lid is closed?

Denis
Sorry, I meant that when I closed the lid the power options didn't automatically change but I now realise were not at that point yet.

I have just done another test. Connected the HDMI created only one log information at 18:53. Disconnecting them created a further three. All event 65 as it seems.

Here is the log, the ones I have highlighted are from the recent test.
 

Attachments

  • log.fw.png
    log.fw.png
    149.6 KB · Views: 1

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
I'll respond by the end of the week. I'm unexpectedly tied up til then.
- I'll post the list of shortcuts to switching between displays [I think this will be a link to a tutorial]
- I'll post a script to turn off sleep when lid is closed together with an "Event viewer, Custom view" definition for that Event 112 and a guide to telling that Event to run a Task scheduler task when the event happens. That will automate your on-connection arrangements.
- I'll post a script to turn back on sleep when lid is closed together with some comments about using it.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
I'll respond by the end of the week. I'm unexpectedly tied up til then.
- I'll post the list of shortcuts to switching between displays [I think this will be a link to a tutorial]
- I'll post a script to turn off sleep when lid is closed together with an "Event viewer, Custom view" definition for that Event 112 and a guide to telling that Event to run a Task scheduler task when the event happens. That will automate your on-connection arrangements.
- I'll post a script to turn back on sleep when lid is closed together with some comments about using it.

Denis
Perfect thanks!
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
I'll post the list of shortcuts to switching between displays [I think this will be a link to a tutorial]
These are my display switching shortcuts - they use the built-in DisplaySwitch.exe command.
There is no difference between Windows 10 & Windows 11 in this respect.

Create a Display Switch shortcut - TenForumsTutorials

1 PC display
DisplaySwitch.exe /internal

2 Duplicate displays
DisplaySwitch.exe /clone

3 Extend display
DisplaySwitch.exe /extend

4 External display
DisplaySwitch.exe /external


DisplaySwitch [Win-P dialog]
DisplaySwitch.exe

Settings, System, Display dialog
ms-settings:display


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675

morgancurtis10

Member
Thread Starter
Local time
12:40 PM
Posts
15
OS
Windows 11
These are my display switching shortcuts - they use the built-in DisplaySwitch.exe command.
There is no difference between Windows 10 & Windows 11 in this respect.

Create a Display Switch shortcut - TenForumsTutorials

1 PC display
DisplaySwitch.exe /internal

2 Duplicate displays
DisplaySwitch.exe /clone

3 Extend display
DisplaySwitch.exe /extend

4 External display
DisplaySwitch.exe /external


DisplaySwitch [Win-P dialog]
DisplaySwitch.exe

Settings, System, Display dialog
ms-settings:display

Denis
Thanks, I have followed the tutorial
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Huawei Matebook Pro
    CPU
    Intel(R) Core(TM) i7-10510U
    Memory
    16 Gb
    Graphics Card(s)
    NVIDIA GeForce MX250
    Sound Card
    Realtek Audio

Try3

Well-known member
Power User
VIP
Local time
12:40 PM
Posts
521
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.675
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
 

Attachments

  • LidCloseAction-Sleep.bat
    172 bytes · Views: 1
  • LidCloseAction-DoNothing.bat
    172 bytes · Views: 1
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.675
Top Bottom