Python 定时关机:到点自动关机 / 重启
import os
import time
from datetime import datetime
def shutdown_at(hour, minute, restart=False):
while True:
now = datetime.now()
if now.hour == hour and now.minute == minute:
cmd = 'shutdown /r /t 60' if restart else 'shutdown /s /t 60'
os.system(cmd)
print("60 秒后关机/重启,取消请运行 shutdown /a")
break
time.sleep(20)
# 每晚 23:00 自动关机
shutdown_at(23, 0)

更新时间:2026-09-14 13:41:53