Python快速启停应用
def run(para=""): win32api.ShellExecute(0, 'open', tarExe, para,'',1)
def app_close(app): win32api.SendMessage(app, win32con.WM_CLOSE, 0, 0)
def scroll(tar, scrol, isUp):
SB_LINEUP, SB_LINEDOWN = 0, 1
win32api.SendMessage(tar, win32con.WM_VSCROLL, SB_LINEUP if isUp else SB_LINEDOWN, scrol); time.sleep(0.05)
def view_scroll(view, isUp):
ID__PREV, ID__NEXT = 135, 136
win32api.SendMessage(view, win32con.WM_COMMAND, (ID__PREV if isUp else ID__NEXT), 0); time.sleep(0.05)
def app_one_run():
run()
while True:
time.sleep(1)
app = win32gui.FindWindow(None, "run")
if app: break
time.sleep(1)
#win32gui.SetForegroundWindow(app)
#for i in range(0,5): mousewheel(+1)
#for i in range(0,5): mousewheel(-1)
thumb = win32gui.FindWindowEx(app, 0, None, "THUMBVIEW")
scrl = win32gui.FindWindowEx(thumb, 0, "ScrollBar", None)
for i in range(0,5): scroll(thumb, scrl, True)
for i in range(0,5): scroll(thumb, scrl, False)
thread,appId =win32process.GetWindowThreadProcessId(app)
app_close(app)
cnt = 0
while True:
if not psutil.pid_exists(appId): break
time.sleep(random.random()*2)
cnt += 1
if cnt>10:
print("exit hang!")
assert(0)