Use Windows Task Scheduler To Put Windows To Sleep Without Batch File

2

3

How can I use Task Scheduler to put Windows 10 to sleep at a specific time without using a batch file?

Jazimov

Posted 2016-04-26T12:42:58.280

Reputation: 283

Answers

5

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.)

Ben N

Posted 2016-04-26T12:42:58.280

Reputation: 32 973

This works fine for sleeping, but how can I wake it from this sleep? Also with task scheduler. – Alex Bartiş – 2017-12-04T13:08:52.247

@AlexBartiş Though I haven't tested it, this HTG guide looks promising.

– Ben N – 2017-12-04T16:09:11.277

thanks, I've tried it before asking you, and it doesn't work for me. I'm on the latest W10 Home Edition, and it doesn't work if I manually put it to sleep or if I use your task to put it to sleep. – Alex Bartiş – 2017-12-04T20:14:35.960

@AlexBartiş Hmm, in that case, I would suggest asking a new question with that information, as you have done. Hopefully somebody knows the answer. – Ben N – 2017-12-05T01:19:00.597

If anyone's still interested, here's an alternative way of scheduling. https://www.groovypost.com/howto/schedule-wake-sleep-windows-automatically/

– anonymous coward – 2018-05-29T20:21:24.713

1

Note, for windows 10 this method has same bug not having the standby feature so it won't wake your computer if you also schedule that on your task scheduler. Use Sysinternals Pstools : https://stackoverflow.com/questions/32360306/sleep-via-shortcut-causes-schedule-tasks-to-not-wake-computer

– zcahfg2 – 2019-01-19T15:55:02.640

0

  1. Create a new task.
  2. Decide how you want the General tab to be set (I recommend selecting "Run whether user is logged on or not").
  3. I chose "Run with highest privileges", but this depends on your requirements.
  4. Create a Trigger that describes when you want the task to run.
  5. 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!

  1. Save your task and test-run it.

Jazimov

Posted 2016-04-26T12:42:58.280

Reputation: 283

2Danger! rundll32 is deprecated. Also, sleep is not a valid argument to SetSuspendState, which only takes three Booleans. Therefore, passing a string works only by chance, and probably demolishes the function's stack. – Ben N – 2016-04-26T13:11:53.653