如果您有pywin32和ctypes,则无需诉诸shell执行:import ctypes
import win32api
import win32security
def suspend(hibernate=False):
"""Puts Windows to Suspend/Sleep/Standby or Hibernate.
Parameters
----------
hibernate: bool, default False
If False (default), system will enter Suspend/Sleep/Standby state.
If True, system will Hibernate, but only if Hibernate is enabled in the
system settings. If it's not, system will Sleep.
Example:
--------
>>> suspend()
"""
# Enable the SeShutdown privilege (which must be present in your
# token in the first place)
priv_flags = (win32security.TOKEN_ADJUST_PRIVILEGES |
win32security.TOKEN_QUERY)
hToken = win32security.OpenProcessToken(
win32api.GetCurrentProcess(),
priv_flags
)</