Switching off the sleep mode when an external display is connected The 2019 Stack Overflow...

It's possible to achieve negative score?

How come people say “Would of”?

Could JWST stay at L2 "forever"?

Spanish for "widget"

What does "sndry explns" mean in one of the Hitchhiker's guide books?

Does it makes sense to buy a new cycle to learn riding?

Deadlock Graph and Interpretation, solution to avoid

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

In microwave frequencies, do you use a circulator when you need a (near) perfect diode?

What can other administrators access on my machine?

Does light intensity oscillate really fast since it is a wave?

Idiomatic way to prevent slicing?

Can't find the latex code for the ⍎ (down tack jot) symbol

What is the meaning of Triage in Cybersec world?

What do hard-Brexiteers want with respect to the Irish border?

How to create dashed lines/arrows in Illustrator

How long do I have to send payment?

Dual Citizen. Exited the US on Italian passport recently

How to manage monthly salary

Limit the amount of RAM Mathematica may access?

Patience, young "Padovan"

Why did Howard Stark use all the Vibranium they had on a prototype shield?

Is this food a bread or a loaf?

Geography at the pixel level



Switching off the sleep mode when an external display is connected



The 2019 Stack Overflow Developer Survey Results Are InEasy way to switch power plan in Windows 10Run a script when second monitor is connectedExternal Monitor display issue when closing the lid of laptopPrevent laptop from going to sleep when I close the lid, but only if I'm connected to an external displaySecondary monitor shuts off when laptop lid closeHow to tell Windows 7 “sleep when laptop is closed, unless there's an external monitor connected; then use that”?Avoiding sleep when lid is close and no one is logged inHow to “sleep” a Windows 8 laptop without closing the lidautomate so that if and only if external monitor is attached, closing laptop lid does nothingHow to make laptop not to sleep when closing the lid, but additional display is connected?Can I tell Windows 10 - 'If I close the lid on my laptop, go to sleep IF I don't have an external monitor attached'?Windows 10 goes back to extended display mode when back from sleep





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















When I'm connected to an external display, I would like to close the laptop without it going to sleep.
When I'm not connected to an external display, I would like to have closing the lid put the laptop to sleep.

I know I can achieve this by manually switching the power settings, but I'd like something automatic.
Any idea? Сan we track the external display connection?

Windows 10










share|improve this question





























    2















    When I'm connected to an external display, I would like to close the laptop without it going to sleep.
    When I'm not connected to an external display, I would like to have closing the lid put the laptop to sleep.

    I know I can achieve this by manually switching the power settings, but I'd like something automatic.
    Any idea? Сan we track the external display connection?

    Windows 10










    share|improve this question

























      2












      2








      2








      When I'm connected to an external display, I would like to close the laptop without it going to sleep.
      When I'm not connected to an external display, I would like to have closing the lid put the laptop to sleep.

      I know I can achieve this by manually switching the power settings, but I'd like something automatic.
      Any idea? Сan we track the external display connection?

      Windows 10










      share|improve this question














      When I'm connected to an external display, I would like to close the laptop without it going to sleep.
      When I'm not connected to an external display, I would like to have closing the lid put the laptop to sleep.

      I know I can achieve this by manually switching the power settings, but I'd like something automatic.
      Any idea? Сan we track the external display connection?

      Windows 10







      windows-10 laptop sleep external-display






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 25 '17 at 13:39









      Starcev MishaStarcev Misha

      132




      132






















          2 Answers
          2






          active

          oldest

          votes


















          0















          1. Determine (or create, if necessary) two power schemes, one with sleep button enabled, one with disabled.


          2. Using command powercfg /l determine GUID's of these schemes.


          3. Install AutoHotKey and set up launching this monitoring script after each start of Windows. Every time the monitor is connected and disconnected, AutoHotKey will run the script for you, switching the power scheme:




          OnMessage(0x219, "MsgMonitor")
          MsgMonitor(wParam, lParam, msg)
          {
          if (wParam = 7) {
          Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
          } Else {
          Run, powercfg /s 381b4222-0001-2222-3333-000000000000
          }
          MsgBox check %wParam% and %lParam% and decide to run programs with %msg%
          }
          ;wParam: 7 lParam: 0 monitor connected
          ;wParam: 32772 lParam: 8977536 should be on disconected


          Important: Replace sample GUID's in the above code with GUID's you determined in step 2.



          Sources:




          • Run a script when second monitor is connected


          • Easy way to switch power plan in Windows 10







          share|improve this answer































            0














            @miroxlav solution did not work for me. I changed the script as follows.




            • You still have to create two power saving configs

            • The AutoHotKey script is typically executed at startup.

            • The caught event is a bit different (WM_DISPLAYCHANGE)

            • You have to identify your main monitor instance nam from powershell get-WmiObject or device manager or...

            • power config UUIDs are hard coded in script too.


                /*
            Please note that it is not sufficient to count the number of monitors because the
            main monitors goes off line when you close the lid.
            Which resets the count to... 1
            So instead, we just make our decision on the presence of a different monitor than the known
            main one (hardcoded id, SN is a poor criterion).
            */

            /*
            Subscribe to windows event
            0x7E = WM_DISPLAYCHANGE
            */
            OnMessage(0x7E, "MsgMonitor")

            MsgMonitor(wParam, lParam, msg) {

            /* Sleep 2 sec because there is a delay before display is known to WMI */
            Sleep 2000

            /* default */
            strComputer := "."

            /* This is the one for my PC... */
            myMonitor := "DISPLAYLGD056E4&13419694&0&UID265988_0"

            objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" . strComputer . "rootwmi")
            colItems := objWMIService.ExecQuery("Select * FROM WMIMonitorID")._NewEnum

            hasExternal := false

            While colItems[objItem]
            if objItem.instanceName != myMonitor {
            hasExternal := True
            }

            if ( hasExternal ) {
            /* this is the power config that does not set laptop to sleep on lid closing */event
            Run, powercfg /s a48ebd52-0590-400d-b032-ac7f4302c0e1
            } Else {
            /* this instead is the power config that does set laptop to sleep on lid closing event */
            Run, powercfg /s 377a8558-bff4-4f51-ab43-626b1aa5a65f
            }

            }





            share|improve this answer
























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1253453%2fswitching-off-the-sleep-mode-when-an-external-display-is-connected%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0















              1. Determine (or create, if necessary) two power schemes, one with sleep button enabled, one with disabled.


              2. Using command powercfg /l determine GUID's of these schemes.


              3. Install AutoHotKey and set up launching this monitoring script after each start of Windows. Every time the monitor is connected and disconnected, AutoHotKey will run the script for you, switching the power scheme:




              OnMessage(0x219, "MsgMonitor")
              MsgMonitor(wParam, lParam, msg)
              {
              if (wParam = 7) {
              Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
              } Else {
              Run, powercfg /s 381b4222-0001-2222-3333-000000000000
              }
              MsgBox check %wParam% and %lParam% and decide to run programs with %msg%
              }
              ;wParam: 7 lParam: 0 monitor connected
              ;wParam: 32772 lParam: 8977536 should be on disconected


              Important: Replace sample GUID's in the above code with GUID's you determined in step 2.



              Sources:




              • Run a script when second monitor is connected


              • Easy way to switch power plan in Windows 10







              share|improve this answer




























                0















                1. Determine (or create, if necessary) two power schemes, one with sleep button enabled, one with disabled.


                2. Using command powercfg /l determine GUID's of these schemes.


                3. Install AutoHotKey and set up launching this monitoring script after each start of Windows. Every time the monitor is connected and disconnected, AutoHotKey will run the script for you, switching the power scheme:




                OnMessage(0x219, "MsgMonitor")
                MsgMonitor(wParam, lParam, msg)
                {
                if (wParam = 7) {
                Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
                } Else {
                Run, powercfg /s 381b4222-0001-2222-3333-000000000000
                }
                MsgBox check %wParam% and %lParam% and decide to run programs with %msg%
                }
                ;wParam: 7 lParam: 0 monitor connected
                ;wParam: 32772 lParam: 8977536 should be on disconected


                Important: Replace sample GUID's in the above code with GUID's you determined in step 2.



                Sources:




                • Run a script when second monitor is connected


                • Easy way to switch power plan in Windows 10







                share|improve this answer


























                  0












                  0








                  0








                  1. Determine (or create, if necessary) two power schemes, one with sleep button enabled, one with disabled.


                  2. Using command powercfg /l determine GUID's of these schemes.


                  3. Install AutoHotKey and set up launching this monitoring script after each start of Windows. Every time the monitor is connected and disconnected, AutoHotKey will run the script for you, switching the power scheme:




                  OnMessage(0x219, "MsgMonitor")
                  MsgMonitor(wParam, lParam, msg)
                  {
                  if (wParam = 7) {
                  Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
                  } Else {
                  Run, powercfg /s 381b4222-0001-2222-3333-000000000000
                  }
                  MsgBox check %wParam% and %lParam% and decide to run programs with %msg%
                  }
                  ;wParam: 7 lParam: 0 monitor connected
                  ;wParam: 32772 lParam: 8977536 should be on disconected


                  Important: Replace sample GUID's in the above code with GUID's you determined in step 2.



                  Sources:




                  • Run a script when second monitor is connected


                  • Easy way to switch power plan in Windows 10







                  share|improve this answer














                  1. Determine (or create, if necessary) two power schemes, one with sleep button enabled, one with disabled.


                  2. Using command powercfg /l determine GUID's of these schemes.


                  3. Install AutoHotKey and set up launching this monitoring script after each start of Windows. Every time the monitor is connected and disconnected, AutoHotKey will run the script for you, switching the power scheme:




                  OnMessage(0x219, "MsgMonitor")
                  MsgMonitor(wParam, lParam, msg)
                  {
                  if (wParam = 7) {
                  Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
                  } Else {
                  Run, powercfg /s 381b4222-0001-2222-3333-000000000000
                  }
                  MsgBox check %wParam% and %lParam% and decide to run programs with %msg%
                  }
                  ;wParam: 7 lParam: 0 monitor connected
                  ;wParam: 32772 lParam: 8977536 should be on disconected


                  Important: Replace sample GUID's in the above code with GUID's you determined in step 2.



                  Sources:




                  • Run a script when second monitor is connected


                  • Easy way to switch power plan in Windows 10








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 25 '17 at 14:02









                  miroxlavmiroxlav

                  8,05153074




                  8,05153074

























                      0














                      @miroxlav solution did not work for me. I changed the script as follows.




                      • You still have to create two power saving configs

                      • The AutoHotKey script is typically executed at startup.

                      • The caught event is a bit different (WM_DISPLAYCHANGE)

                      • You have to identify your main monitor instance nam from powershell get-WmiObject or device manager or...

                      • power config UUIDs are hard coded in script too.


                          /*
                      Please note that it is not sufficient to count the number of monitors because the
                      main monitors goes off line when you close the lid.
                      Which resets the count to... 1
                      So instead, we just make our decision on the presence of a different monitor than the known
                      main one (hardcoded id, SN is a poor criterion).
                      */

                      /*
                      Subscribe to windows event
                      0x7E = WM_DISPLAYCHANGE
                      */
                      OnMessage(0x7E, "MsgMonitor")

                      MsgMonitor(wParam, lParam, msg) {

                      /* Sleep 2 sec because there is a delay before display is known to WMI */
                      Sleep 2000

                      /* default */
                      strComputer := "."

                      /* This is the one for my PC... */
                      myMonitor := "DISPLAYLGD056E4&13419694&0&UID265988_0"

                      objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" . strComputer . "rootwmi")
                      colItems := objWMIService.ExecQuery("Select * FROM WMIMonitorID")._NewEnum

                      hasExternal := false

                      While colItems[objItem]
                      if objItem.instanceName != myMonitor {
                      hasExternal := True
                      }

                      if ( hasExternal ) {
                      /* this is the power config that does not set laptop to sleep on lid closing */event
                      Run, powercfg /s a48ebd52-0590-400d-b032-ac7f4302c0e1
                      } Else {
                      /* this instead is the power config that does set laptop to sleep on lid closing event */
                      Run, powercfg /s 377a8558-bff4-4f51-ab43-626b1aa5a65f
                      }

                      }





                      share|improve this answer




























                        0














                        @miroxlav solution did not work for me. I changed the script as follows.




                        • You still have to create two power saving configs

                        • The AutoHotKey script is typically executed at startup.

                        • The caught event is a bit different (WM_DISPLAYCHANGE)

                        • You have to identify your main monitor instance nam from powershell get-WmiObject or device manager or...

                        • power config UUIDs are hard coded in script too.


                            /*
                        Please note that it is not sufficient to count the number of monitors because the
                        main monitors goes off line when you close the lid.
                        Which resets the count to... 1
                        So instead, we just make our decision on the presence of a different monitor than the known
                        main one (hardcoded id, SN is a poor criterion).
                        */

                        /*
                        Subscribe to windows event
                        0x7E = WM_DISPLAYCHANGE
                        */
                        OnMessage(0x7E, "MsgMonitor")

                        MsgMonitor(wParam, lParam, msg) {

                        /* Sleep 2 sec because there is a delay before display is known to WMI */
                        Sleep 2000

                        /* default */
                        strComputer := "."

                        /* This is the one for my PC... */
                        myMonitor := "DISPLAYLGD056E4&13419694&0&UID265988_0"

                        objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" . strComputer . "rootwmi")
                        colItems := objWMIService.ExecQuery("Select * FROM WMIMonitorID")._NewEnum

                        hasExternal := false

                        While colItems[objItem]
                        if objItem.instanceName != myMonitor {
                        hasExternal := True
                        }

                        if ( hasExternal ) {
                        /* this is the power config that does not set laptop to sleep on lid closing */event
                        Run, powercfg /s a48ebd52-0590-400d-b032-ac7f4302c0e1
                        } Else {
                        /* this instead is the power config that does set laptop to sleep on lid closing event */
                        Run, powercfg /s 377a8558-bff4-4f51-ab43-626b1aa5a65f
                        }

                        }





                        share|improve this answer


























                          0












                          0








                          0







                          @miroxlav solution did not work for me. I changed the script as follows.




                          • You still have to create two power saving configs

                          • The AutoHotKey script is typically executed at startup.

                          • The caught event is a bit different (WM_DISPLAYCHANGE)

                          • You have to identify your main monitor instance nam from powershell get-WmiObject or device manager or...

                          • power config UUIDs are hard coded in script too.


                              /*
                          Please note that it is not sufficient to count the number of monitors because the
                          main monitors goes off line when you close the lid.
                          Which resets the count to... 1
                          So instead, we just make our decision on the presence of a different monitor than the known
                          main one (hardcoded id, SN is a poor criterion).
                          */

                          /*
                          Subscribe to windows event
                          0x7E = WM_DISPLAYCHANGE
                          */
                          OnMessage(0x7E, "MsgMonitor")

                          MsgMonitor(wParam, lParam, msg) {

                          /* Sleep 2 sec because there is a delay before display is known to WMI */
                          Sleep 2000

                          /* default */
                          strComputer := "."

                          /* This is the one for my PC... */
                          myMonitor := "DISPLAYLGD056E4&13419694&0&UID265988_0"

                          objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" . strComputer . "rootwmi")
                          colItems := objWMIService.ExecQuery("Select * FROM WMIMonitorID")._NewEnum

                          hasExternal := false

                          While colItems[objItem]
                          if objItem.instanceName != myMonitor {
                          hasExternal := True
                          }

                          if ( hasExternal ) {
                          /* this is the power config that does not set laptop to sleep on lid closing */event
                          Run, powercfg /s a48ebd52-0590-400d-b032-ac7f4302c0e1
                          } Else {
                          /* this instead is the power config that does set laptop to sleep on lid closing event */
                          Run, powercfg /s 377a8558-bff4-4f51-ab43-626b1aa5a65f
                          }

                          }





                          share|improve this answer













                          @miroxlav solution did not work for me. I changed the script as follows.




                          • You still have to create two power saving configs

                          • The AutoHotKey script is typically executed at startup.

                          • The caught event is a bit different (WM_DISPLAYCHANGE)

                          • You have to identify your main monitor instance nam from powershell get-WmiObject or device manager or...

                          • power config UUIDs are hard coded in script too.


                              /*
                          Please note that it is not sufficient to count the number of monitors because the
                          main monitors goes off line when you close the lid.
                          Which resets the count to... 1
                          So instead, we just make our decision on the presence of a different monitor than the known
                          main one (hardcoded id, SN is a poor criterion).
                          */

                          /*
                          Subscribe to windows event
                          0x7E = WM_DISPLAYCHANGE
                          */
                          OnMessage(0x7E, "MsgMonitor")

                          MsgMonitor(wParam, lParam, msg) {

                          /* Sleep 2 sec because there is a delay before display is known to WMI */
                          Sleep 2000

                          /* default */
                          strComputer := "."

                          /* This is the one for my PC... */
                          myMonitor := "DISPLAYLGD056E4&13419694&0&UID265988_0"

                          objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\" . strComputer . "rootwmi")
                          colItems := objWMIService.ExecQuery("Select * FROM WMIMonitorID")._NewEnum

                          hasExternal := false

                          While colItems[objItem]
                          if objItem.instanceName != myMonitor {
                          hasExternal := True
                          }

                          if ( hasExternal ) {
                          /* this is the power config that does not set laptop to sleep on lid closing */event
                          Run, powercfg /s a48ebd52-0590-400d-b032-ac7f4302c0e1
                          } Else {
                          /* this instead is the power config that does set laptop to sleep on lid closing event */
                          Run, powercfg /s 377a8558-bff4-4f51-ab43-626b1aa5a65f
                          }

                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 2 days ago









                          Alain PannetierAlain Pannetier

                          6722920




                          6722920






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1253453%2fswitching-off-the-sleep-mode-when-an-external-display-is-connected%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                              Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

                              looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...