
我按照本指南創建了 2 個睡眠和喚醒任務:https://www.groovypost.com/howto/schedule-wake-sleep-windows-automatically/
如果我獨立運行睡眠任務,PC 將進入睡眠狀態並透過滑鼠移動事件喚醒。
如果我安排喚醒任務並將電腦設定為睡眠鍵盤按鈕,它將透過安排任務喚醒。
因此,任務可以獨立運行,但不能在任務事件鏈中運行。
我嘗試過的:
- 停用休眠功能
powercfg -h off
- 設定 -> 電源選項中允許的喚醒計時器(設定為啟用)
- 啟用 BIOS 中與事件計時器和喚醒相關的所有內容
- 在睡眠和喚醒任務之間使用超過 5 分鐘的暫停
- 薩滿拿著手鼓跳舞
附加螢幕截圖:
可下載的軟體不是一個選項。 PC 和筆記型電腦上的行為相同。到現在為止,掙扎已經持續了2天了…
答案1
$script = '$signature = @"
[DllImport("powrprof.dll")]
public static extern bool SetSuspendState(bool Hibernate,bool ForceCritical,bool DisableWakeEvent);
"@
$func = Add-Type -memberDefinition $signature -namespace "Win32Functions" -name "SetSuspendStateFunction" -passThru
$func::SetSuspendState($false,$true,$false)'
$bytes = [System.Text.Encoding]::Unicode.GetBytes($script)
$encodedCommand = [Convert]::ToBase64String($bytes)
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-encodedCommand $encodedCommand"
$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At 16:43
Register-ScheduledTask -TaskName "Sleep" -Action $action -Trigger $trigger -Force
$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c echo hello"
$settings = New-ScheduledTaskSettingsSet -WakeToRun
$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At 16:44
Register-ScheduledTask -TaskName "Wake" -Action $action -Settings $settings -Trigger $trigger -Force
奇蹟般有效 :)
也不要使用 RUNDLL32 因為
Rundll32 只能從 DLL 中呼叫明確編寫為由 Rundll32 呼叫的函數。
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rundll32#remarks