关于重启系统服务

来源:互联网 发布:fc2最新域名网站 编辑:程序博客网 时间:2024/04/30 09:46

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

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可以知道服务的状态,很方便

原创粉丝点击