python实现windows关机_用Python在Windows下实现定时关机

用Python在Windows下实现定时关机

Python

#定时关机2014-04-06 23:40

直接上代码:

~/Desktop/shutdown.py.html

"""Target OS: WinXP

Python: Ver 2.4

Author: violet_kz ( violet_kz@gmail.com ) http://yige.org/python/

Describe: this python script call the command "shutdown.exe" to halt the

system . """

import os import sys

if __name__ == '__main__':

print '|--------------|= Shutdown =|---------------|'

print ' 0: At once ( or \'Enter\' key )'

print ' 1: After 1 hour'

print ' 2: After 2 hours'

print ' 3: Others'

print ' 5: Cancel a shutdown command'

print ' q(Q): Quit'

print '|-------------------------------------------|'

while 1: _input = raw_input('pls choose:')

if _input == 'q' or _input == 'Q':

sys.exit( 0 )

if _input in ['0','','1','2','3','5']:

break else:

print "Invaild input,pls input again :) or press \'q(Q)\' to exit"

if _input == '' or _input == '0':

time = 3 elif _input == '1':

time = 1 * 3600

elif _input == '2':

time =2 * 3600

elif _input == '3':

while 1: _hours = raw_input('After(hours) : ');

if _hours == 'q' or _hours == 'Q':

sys.exit( 1 )

if float(_hours) < 0 or float(_hours) >24:

print 'Invaild input,pls input again :) or press \'q(Q)\' to exit'

else: time = float( _hours ) * 3600

print 'ok~~, The system will be shutdowned after %s hour(s)' % _hours

break if _input == '5':

os.system( 'shutdown.exe -a' )

sys.exit( 1 )

_shutdownStr = 'shutdown.exe -f -s -t %s' % int(time)

print _shutdownStr

os.system( _shutdownStr )

相关文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值