윈도우에서 프로세서 id를 찾아서 강제 종료하는 방법과 프로그램 자동 실행해주는 방법
import time
import socket
import os
import subprocess
import win32gui
def winEnumHandler( hwnd, ctx ):
global start_py
global xyzchecker
if win32gui.IsWindowVisible( hwnd ):
#print ( hex( hwnd ), win32gui.GetWindowText( hwnd ) )
if "{윈도우창이름}" in win32gui.GetWindowText( hwnd ):
start_py = "on"
if "xyz" in win32gui.GetWindowText( hwnd ):
xyzchecker = "on"
print("오토비 0.0.0.1 프로그램/뷰어 종료 자동실행 시작 ...")
time.sleep(1)
while True:
start_py = "off"
xyzchecker = "off"
try:
win32gui.EnumWindows( winEnumHandler, None ) #start.py 재실행
if start_py == "off" :
os.system('start cmd /c start.py auto')
except Exception as e:
print(e)
print("check adb syntax")
output = subprocess.check_output(['tasklist', '/fi', 'imagename eq svchost.exe', '/svc', '/nh'])
try:
for line in output.decode().strip().split('\n'):
if '{프로그램이름} in line:
pid = line.split()[1]
print('PID:', pid)
#os.system(f"taskkill /pid {pid} /f")
subprocess.Popen(['taskkill', '/F', '/PID', str(pid)])
except Exception as e:
print(e)
time.sleep(600)