我写了一个这样的 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"