win 笔记本有办法只有链接外部显示器,合上才不休眠吗?

2023-04-07 22:11:26 +08:00
 jsjcjsjc
目前的设置是,不管是否连接显示器,合上都不休眠...有办法只有链接外部显示器,合上才不休眠吗?
978 次点击
所在节点    问与答
9 条回复
DemianL
2023-04-07 22:14:11 +08:00
emmm 系统设置里面有个合上盖子的选项 你可以选择什么都不做它就不休眠了...
FlyPuff
2023-04-07 22:24:13 +08:00
新电脑么?现在的新电脑都是只支持合盖现代(关屏幕)休眠了吧。。
jsjcjsjc
2023-04-07 23:34:31 +08:00
@DemianL 关键是我想考虑链接外部显示器的问题~~
ysc3839
2023-04-08 01:04:48 +08:00
推荐一下自己开发的项目 https://github.com/ysc3839/ProjectionAwake
ISVStar
2023-04-08 04:00:50 +08:00
我写了一个这样的 PowerShell 脚本,不完全符合你的要求。运行脚本后,忽略下一次合盖睡眠。

# grab powercfg guids necessary for lid switch action
# https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action

#capture the active scheme GUID
$activeScheme = cmd /c "powercfg /getactivescheme"
$regEx = '(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}'
$asGuid = [regex]::Match($activeScheme,$regEx).Value

#relative GUIDs for Lid Close settings
$pwrGuid = '4f971e89-eebd-4455-a8de-9e59040e7347'
$lidClosedGuid = '5ca83367-6e45-459f-a27b-476b1d01c936'

# DC Value // On Battery // 0 = do nothing
cmd /c "powercfg /setdcvalueindex $asGuid $pwrGuid $lidClosedGuid 0"
# AC Value // While plugged in // 0 = do nothing
cmd /c "powercfg /setacvalueindex $asGuid $pwrGuid $lidClosedGuid 0"

#apply settings
cmd /c "powercfg /s $asGuid"

echo "You can now close the lid ..."
$ScreenCount = (Get-CimInstance -Namespace root\wmi -ClassName wmiMonitorID | Measure-Object).Count
Do
{
$ScreenCountRecur = (Get-CimInstance -Namespace root\wmi -ClassName wmiMonitorID | Measure-Object).Count
Start-Sleep -Seconds 1
}
While($ScreenCountRecur -ge $ScreenCount)

# DC Value // On Battery // 1 = sleep
cmd /c "powercfg /setdcvalueindex $asGuid $pwrGuid $lidClosedGuid 1"
# AC Value // While plugged in // 1 = sleep
cmd /c "powercfg /setacvalueindex $asGuid $pwrGuid $lidClosedGuid 1"
ISVStar
2023-04-08 04:02:19 +08:00
#capture the active scheme GUID

$activeScheme = cmd /c "powercfg /getactivescheme"

$regEx = '(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}'

$asGuid = [regex]::Match($activeScheme,$regEx).Value



#relative GUIDs for Lid Close settings

$pwrGuid = '4f971e89-eebd-4455-a8de-9e59040e7347'

$lidClosedGuid = '5ca83367-6e45-459f-a27b-476b1d01c936'



# DC Value // On Battery // 0 = do nothing

cmd /c "powercfg /setdcvalueindex $asGuid $pwrGuid $lidClosedGuid 0"

# AC Value // While plugged in // 0 = do nothing

cmd /c "powercfg /setacvalueindex $asGuid $pwrGuid $lidClosedGuid 0"



#apply settings

cmd /c "powercfg /s $asGuid"



echo "You can now close the lid ..."

$ScreenCount = (Get-CimInstance -Namespace root\wmi -ClassName wmiMonitorID | Measure-Object).Count

Do

{

$ScreenCountRecur = (Get-CimInstance -Namespace root\wmi -ClassName wmiMonitorID | Measure-Object).Count

Start-Sleep -Seconds 1

}

While($ScreenCountRecur -ge $ScreenCount)



# DC Value // On Battery // 1 = sleep

cmd /c "powercfg /setdcvalueindex $asGuid $pwrGuid $lidClosedGuid 1"

# AC Value // While plugged in // 1 = sleep

cmd /c "powercfg /setacvalueindex $asGuid $pwrGuid $lidClosedGuid 1"
jsjcjsjc
2023-04-08 11:10:15 +08:00
@ISVStar 感谢大佬哈
yinmin
2023-04-08 17:23:26 +08:00
换一个思路:笔记本插上电源时,合上电脑不休眠;如果用上电池,合上电脑才休眠。这种场景是不是可以满足你大多数的场景?

根据插电源来判断,在 windows 设置里可以配置。
jsjcjsjc
2023-04-09 10:45:31 +08:00
@yinmin 目前已经是这么设置的了,感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/930697

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX