How can I use Task Scheduler to put Windows 10 to sleep at a specific time without using a batch file?
2 Answers
Set up your time in Task Scheduler's Triggers window as normal. On the General tab, it's probably easiest to make the task run as SYSTEM, and run whether the user is logged in or not. Highest privileges are not necessary.
Since rundll32 is deprecated and treacherous in general, we'll use PowerShell to invoke the sleep function correctly. Set the Program/script field to powershell.exe. Put this in the Add arguments field:
-command add-type -assemblyname System.Windows.Forms; [System.Windows.Forms.Application]::SetSuspendState([System.Windows.Forms.PowerState]::Suspend, $false, $false)
The add-type command imports the Forms assembly, which contains a managed SetSuspendState method. The second command calls that method, putting the computer to sleep but allowing wake events to exit sleep. (If you don't want wake events to keep working, change the last $false to $true.)
- 42,308
- Create a new task.
- Decide how you want the General tab to be set (I recommend selecting "Run whether user is logged on or not").
- I chose "Run with highest privileges", but this depends on your requirements.
- Create a Trigger that describes when you want the task to run.
- Create a new Action--this is the key step: The Action must be "Start a program".
The "Program/script" value should be: rundll32.exe The "Add arguments (optional):" value should be: powrprof.dll,SetSuspendState sleep The "Start in (optional):" value should be left empty.
IT IS IMPORTANT TO OBSERVE THE CASE OF THE "SetSuspendState" argument! "setsuspendstate" won't work!
- Save your task and test-run it.
- 367