Share via

Task Scheduler: PC sleeps when locked

Anonymous
2023-12-30T01:05:05+00:00

Recently had to do a fresh install of windows 11 and forgot to save instructions to re-do a task scheduler task which puts the PC to sleep when locked with Win + L or similar. Can anyone help me out with step by step instructions on how to add this back? Regards

Edit: I have tried the below and no luck. Task is enabled to run whether user is logged on or not but just locks and no sleep. See below:

Windows for home | Windows 11 | Sleep and Power on, off

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2024-01-13T13:56:12+00:00

    I've fixed it.

    For those reading who want to know:

    1. Open notepad and type Rundll32.exe Powrprof.dll,SetSuspendState Sleep
    2. Save As > Desktop > File type: All files > Name: Sleep.bat
    3. Open task scheduler
    4. Create task
    5. On the "general" tab enter as below and hit the "triggers" tab:

    1. On the "triggers" tab, select "new", enter as below and hit "ok":

    1. "Actions" tab, select "new", enter as below (you will need to "browse" to your location of sleep.bat) and hit "ok":

    1. Check the conditions tab looks like this

    1. Hit "ok".
    2. Test by pressing the windows key and 'L' keyboard keys together
    3. PC should lock and sleep.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-01-01T16:30:15+00:00

    Hi Robinson,

    Still not working I'm afraid.

    When I type psshutdown /? I get the below. Is this what you mean by "agreement terms"? I also don't get an "agree" button as you mentioned.

    Image

    Checked and PsTools is in the environment variables

    Image

    What happened when I tried to run psshutdown -d in CMD

    Image

    So i checked that task scheduler is set to run with highest privileges and it is.

    Image

    PSSHUTDOWN -d runs successfully in an elevated command prompt but I only get the lock screen when I lock the PC.

    Thanks

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-12-31T02:31:59+00:00

    I'm sorry for my mistake. I didn't see that you were using the PsTools utility instead of the shutdown command. For the tasks to work as is worked before, you will need to download the PsTools and add it to the path variable.

    1-Download the PsTools from this link.

    https://learn.microsoft.com/en-us/sysinternals/...

    2-Extract the PsTools.zip and save it on the Local Disk C:

    3-Right-click on Start then click on Run

    4-Type: sysdm.cpl and click on OK

    5-Click on the "Advanced" tab then click on the "Environment Variables..." button in the bottom right corner

    6-Select "Path" under "System variables" at the bottom and then click on the "Edit..." button

    7-A new window will be opened

    8-Click on the "Browse..." button, select the PsTools folder, and click on OK on all windows opened to save the change

    When finished, open the Command Prompt and check if everything is working.

    1-Click on Start, search for Command Prompt and click on that

    2-Type this command and press Enter:

    psshutdown /?

    3-If everything is working correctly, you will see a new window with the agreement terms of the PsTools, and when you click on the "Agree" button you will see the options for the "psshutdown" command

    Then you can use the command "psshutdown -d" command again in the task and your computer will sleep when you lock the screen.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-12-30T22:50:02+00:00

    Hi Robinson,

    Unfortunately, no luck. I just get the lock screen only.

    Image

    Image

    Image

    Edit: I tried shutdown /h /f in cmd and it hibernates the PC. I want to suspend/sleep.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-12-30T04:03:37+00:00

    Hi, Chris. I'm Robinson, and I’m happy to help you today.

    I believe that you are using the wrong command, the option "-d" that you are using is to "Provide the reason for the restart or shutdown".

    Replacing the command "psshutdown -d" with the command "Shutdown /h /f" should fix the problem.

    I hope this information helps. If you have any questions or the problem persists, please let me know and I'll be glad to assist you further.

    Was this answer helpful?

    0 comments No comments