关于重启系统服务

上周写的挫挫的重启服务的代码,只能重启服务,连异常处理都没有,很挫啊很挫

import os
import time
import threading

from time import gmtime, strftime

lock = threading.Lock()

class restart_service():
    def restart_kisaas_service(self):
        while True:
            # make sure the service is start
            print "[start service]"
            print strftime("%a, %d %b %Y %H:%M:%S", gmtime())
            lock.acquire()
            os.system("net start /"Kingsoft Antivirus Client Communication Service/"")
            lock.release()
            # wait for start
            time.sleep(10)
            # stop kisaas service
            print "[stop service]"
            print strftime("%a, %d %b %Y %H:%M:%S", gmtime())
            lock.acquire()
            os.popen("net stop /"Kingsoft Antivirus Client Communication Service/"")
            lock.release()


pRun = restart_service()
pRun.restart_kisaas_service();

 

sc能更好的处理,不用写中间的等待10s,但是程序还没写出来。。。

sc stop wuauserv
sc query wuauserv
sc start wuauserv
sc query wuauserv

 

先记录这么多,sc可以知道服务的状态,很方便

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值