defkill_process(process_name):for proc in psutil.process_iter(['pid','name']):if proc.info['name']== process_name:try:
proc.kill()print(f"Process {process_name} with PID {proc.info['pid']} has been terminated.")except psutil.NoSuchProcess:print(f"Process {process_name} with PID {proc.info['pid']} no longer exists.")except psutil.AccessDenied:print(f"Access denied to terminate process {process_name}.")# 使用
kill_process('AliWorkbench.exe')
defmake_window_visible(title):try:# 尝试连接到已运行的应用程序
app = Application(backend="uia").connect(title=title, timeout=10)
window = app.window(title=title)# 确保窗口是可见的并且处于最前面ifnot window.is_active():
window.set_focus()# 设置焦点,这通常会将窗口带到前台ifnot window.is_visible():
window.show()# 显示窗口(如果它被最小化或隐藏)print(f"Window '{title}' has been made visible and active.")except Exception as e:print(f"Failed to make window '{title}' visible: {e}")# make_window_visible('微信')