Python實現自動關機
阿新 • • 發佈:2018-12-20
首先,我們瞭解下DOS下關機的命令詳情:
shutdown /s /f /t 300/c '還有300s關機'/
shutdown [-i | -l | -s | -r | -a] [-f] [-m \computername] [-t xx] [-c "
mment"] [-d up:xx:yy]
-i 顯示 GUI 介面,必須是第一個選項
-l 登出(不能與選項 -m 一起使用)
-s 關閉此計算機
-r 關閉並重啟動此計算機
-a 放棄系統關機
-m \computername 遠端計算機關機/重啟動/放棄
-t xx 設定關閉的超時為 xx 秒
-c “comment” 關閉註釋(最大 127 個字元)
-f 強制執行的應用程式關閉而沒有警告
p 是一個計劃的關閉程式碼
# -*- coding: utf-8 -*- """ Created on Mon Nov 19 19:56:07 2018 @author: 10091 """ from datetime import datetime,time,date import os tmNow = datetime.now() d = date.today() #設定關閉時間為今天20:26:00 t = time(20,26,0) shtdownTime = datetime.combine(d,t) def ShutDown(): while True: tmNow = datetime.now() timedDelta = (shtdownTime - tmNow).total_seconds() if timedDelta < 60: print '還有59s關機,趕快儲存一下!' os.system('shutdown -s -f -t 30') #break time.sleep(20) else: continue if __name__ == '__main__': ShutDown()