Created
June 25, 2013 15:56
-
-
Save chenzx/5859649 to your computer and use it in GitHub Desktop.
A Python 2.7 script to keep the win32 app running, I use it to monitor my Thunder downloader, since it is keeping crashing due to insufficient disk space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import time | |
| PROCESS_NAME = u"Thunder.exe" | |
| PROCESS_STARTUP_CMDLINE = 'E:\ThunderPortable\ThunderPortable.exe' | |
| def win32app_not_running(): | |
| from win32com.client import GetObject | |
| #Need download http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py2.7.exe/download | |
| WMI = GetObject('winmgmts:') | |
| processes = WMI.InstancesOf('Win32_Process') | |
| # p = WMI.ExecQuery('select * from Win32_Process where Name="Thunder.exe"') | |
| processNames = [process.Properties_('Name').Value for process in processes] | |
| for processName in processNames: | |
| if processName==PROCESS_NAME: | |
| #print "%s is runing" % (PROCESS_NAME) | |
| return False | |
| return True | |
| def start_the_win32app(): | |
| from subprocess import Popen | |
| DETACHED_PROCESS = 0x00000008 | |
| cmd = [ | |
| PROCESS_STARTUP_CMDLINE | |
| ] | |
| p = Popen(cmd,shell=False,stdin=None,stdout=None,stderr=None,close_fds=True,creationflags=DETACHED_PROCESS) | |
| while True: | |
| time.sleep(5) | |
| if win32app_not_running(): | |
| start_the_win32app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment