用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 )
其他实现可参考:http://yige.org/p/629
相关文章
- 用Python获取Google的下拉框自动完成提示文本 2014/02/20
- Python日期操作 2012/12/25
- Python收发邮件 2012/11/27
- Python串口通信 2012/11/27
- 用Python来实现的adsl拨号 2012/11/25
- Python实现的命令行通讯录 2012/11/25
- Python中unicode码转utf8的方法 2012/11/25
- Python二叉树算法实现 2012/11/25
- Python实现的豆瓣电影信息查询 2012/11/25
- Python实现双倍超立方数 2012/11/25