2

I'm in the middle of making a Python script to shutdown, restart, hibernate or put to sleep after a few seconds.

I know its subprocess.call(["shutdown", "/s"]) to shutdown, "/r" to restart and "/h" to hibernate.

How can you put the computer to sleep using call() on Windows 10?

Artyer
  • 31,034
  • 3
  • 47
  • 75
wintermute
  • 21
  • 2
  • `shutdown -s` is the command on windows and you can add the `-t` param to give a time in seconds like `60` for a minute – user1767754 Dec 01 '17 at 19:08

2 Answers2

2

Shutdown doesn't have a function for Sleep integrated however you can use the following: rundll32.exe powrprof.dll,SetSuspendState 0,1,0

dmuensterer
  • 1,875
  • 11
  • 26
1

I know this is asked 3 years ago, but if anyone looking for help, I found a way for sleep with pyautogui

First download and install pyautogui with terminal using command pip download pyautogui and pip install pyautogui

  1. Import it

import pyautogui

  1. use this code (change if you need)
pyautogui.hotkey("alt", "f4")
time.sleep(1)
pyautogui.press("left")
time.sleep(1)
pyautogui.press("enter")

Visit this website if you need any help with pyautogui commands

(I am too new to python coding, there must be easy and more suitable ways to do this. Sorry if I sound so noob.)