自动监听程序,如果程序挂了,就重启

import os
import time
import win32com.client

def check_exsit(process_name):
    WMI = win32com.client.GetObject('winmgmts:')
    processCodeCov = WMI.ExecQuery('select * from Win32_Process where Name like "%{}%"'.format(process_name))
    if len(processCodeCov) > 0:
        return True
    else:
        return False

if __name__ == '__main__':
    while True :
        time.sleep( 10 )
        
        res = check_exsit('CSConsole.exe')
        if not res :
            print(os.system("1_start_cs.bat"))
            time.sleep( 10 )

        res = check_exsit('GSConsole.exe')
        if not res :
            print(os.system("2_start.bat"))
            time.sleep( 10 )

        res = check_exsit('RSConsole.exe')
        if not res :
            print(os.system("3_start_rs.bat"))
            time.sleep( 10 )

  

posted @ 2020-07-28 10:03  沙漠中的雨滴  阅读(287)  评论(0编辑  收藏  举报