1

I'm trying to get a Windows 10 Optiplex 7000 to go to sleep at 10pm every day. I installed nircmd and created a task in task scheduler to run a .bat file with the following command: nircmd.exe monitor async_off

Running this batch file manually (by double clicking it) works just fine. However, if I have the "Run whether user is logged on or not" option selected, and I try to run the task in task scheduler (by clicking the run button) it seems like nothing happens. The batch file is running; I can create files with the output of echo and whoami, but for some reason the nircmd command doesn't seem to execute successfully. If I instead select "Run only when user is logged on" the task works.

The output of whoami is the same for both configurations, so I don't think it's a problem with user permissions. The user who's logged in when the command needs to run doesn't have permission to sleep the computer, so I don't think I can just create the task as them and have it configured to only run when they're logged in.

Does anyone have any ideas I can try? Perhaps a different command I can use to invoke S0 sleep?

(I've already tried psshutdown and rundll32.exe, and neither work because they only invoke S3 sleep which isn't supported by the computer's firmware, according to powercfg -a)

Edit: I've also tried using the following command but with the same results as nircmd. powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

lucdar
  • 11
  • 2
  • Try setting the task to run as `SYSTEM` user and/or enable "run with highest privileges"? Windows is picky about what is allowed to hook into its power api (check system event log for errors like `User-mode process attempted to change the system state`). Also try the suggestions here for suspend/sleep: https://superuser.com/a/463652/673426. Or to only turn off the monitors, you can try this powershell (functionally the same as what you tried): https://www.reddit.com/r/PowerShell/comments/y4g267/how_to_turn_off_monitor/isfv8k5/ – Cpt.Whale Jun 27 '23 at 21:52
  • No luck with the `SYSTEM` user (confirmed to be running as SYSTEM with whom as part of the script) or toggling the "run with highest privileges" checkbox (tried with SYSTEM, Administrator, and unprivileged user. I also tried selecting "Run only when user is logged on selected" and highest privileges with the unprivileged user, and had no luck. I don't see any output like you mentioned in the System event log, though I do see messages when the computer is put to sleep. I also tried with the other command I added in my post which seems to be the same as the powershell you linked. – lucdar Jul 12 '23 at 19:43

0 Answers0