自动更新脚本编写
This commit is contained in:
71
win_click.py
71
win_click.py
@@ -360,7 +360,8 @@ echo 再次确认无残留进程...
|
|||||||
taskkill /F /IM python.exe /T 2>nul
|
taskkill /F /IM python.exe /T 2>nul
|
||||||
taskkill /F /IM pythonw.exe /T 2>nul
|
taskkill /F /IM pythonw.exe /T 2>nul
|
||||||
echo 重新启动系统...
|
echo 重新启动系统...
|
||||||
start "" "{bat_path}"
|
cd /d "{os.path.dirname(bat_path)}"
|
||||||
|
call "{bat_path}"
|
||||||
echo 等待系统启动和微信加载 ({wait_time}秒)...
|
echo 等待系统启动和微信加载 ({wait_time}秒)...
|
||||||
timeout /t {wait_time} /nobreak > nul
|
timeout /t {wait_time} /nobreak > nul
|
||||||
echo 尝试登录微信...
|
echo 尝试登录微信...
|
||||||
@@ -369,32 +370,60 @@ echo 清理临时脚本...
|
|||||||
(goto) 2>nul & del "%~f0" & exit
|
(goto) 2>nul & del "%~f0" & exit
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# 启动临时脚本
|
# 确保临时脚本具有执行权限
|
||||||
|
os.chmod(temp_bat, 0o755)
|
||||||
|
|
||||||
print(f"启动临时脚本执行重启: {temp_bat}")
|
print(f"启动临时脚本执行重启: {temp_bat}")
|
||||||
# 使用startupinfo隐藏cmd窗口,防止重复窗口
|
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
||||||
startupinfo.wShowWindow = subprocess.SW_HIDE
|
|
||||||
|
|
||||||
# 使用subprocess.Popen而不是run,这样不会等待它完成
|
# 创建分离进程运行批处理
|
||||||
subprocess.Popen(["cmd", "/c", temp_bat],
|
try:
|
||||||
shell=True,
|
# 方法1: 使用START命令启动独立进程
|
||||||
creationflags=subprocess.CREATE_NEW_CONSOLE,
|
os.system(f'start "" "{temp_bat}"')
|
||||||
startupinfo=startupinfo)
|
|
||||||
|
|
||||||
# 等待脚本启动
|
# 方法2: 作为备份机制,也使用subprocess启动
|
||||||
print("已启动临时脚本,等待3秒...")
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
time.sleep(3)
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
|
subprocess.Popen(
|
||||||
|
temp_bat,
|
||||||
|
shell=True,
|
||||||
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS,
|
||||||
|
startupinfo=startupinfo
|
||||||
|
)
|
||||||
|
|
||||||
# 直接调用全局终止方法确保干净退出
|
print("已通过两种方法启动临时脚本")
|
||||||
print("终止所有Python相关进程...")
|
except Exception as e:
|
||||||
os.system("taskkill /F /IM python.exe /T 2>nul")
|
print(f"启动临时脚本时出错: {e}")
|
||||||
|
# 尝试直接回退到启动原始脚本
|
||||||
|
try:
|
||||||
|
print(f"尝试直接启动原始脚本: {bat_path}")
|
||||||
|
original_dir = os.getcwd()
|
||||||
|
os.chdir(os.path.dirname(bat_path))
|
||||||
|
subprocess.Popen(
|
||||||
|
f'cmd /c "{bat_path}"',
|
||||||
|
shell=True,
|
||||||
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS
|
||||||
|
)
|
||||||
|
os.chdir(original_dir)
|
||||||
|
except Exception as e2:
|
||||||
|
print(f"启动原始脚本时出错: {e2}")
|
||||||
|
|
||||||
# 结束当前Python相关进程并退出
|
# 等待确保脚本启动
|
||||||
print("结束当前进程...")
|
print("等待4秒确保启动脚本已开始执行...")
|
||||||
terminate_processes()
|
time.sleep(4)
|
||||||
|
|
||||||
|
# 多重终止保障
|
||||||
|
try:
|
||||||
|
# 确保使用系统命令终止所有Python进程
|
||||||
|
print("使用系统命令终止所有Python相关进程...")
|
||||||
|
os.system("taskkill /F /IM python.exe /T 2>nul")
|
||||||
|
os.system("taskkill /F /IM pythonw.exe /T 2>nul")
|
||||||
|
|
||||||
|
# 结束当前Python相关进程
|
||||||
|
print("使用psutil终止当前进程...")
|
||||||
|
terminate_processes()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"终止进程时出错: {e}")
|
||||||
|
|
||||||
# 确保进程退出
|
|
||||||
print("强制退出当前进程")
|
print("强制退出当前进程")
|
||||||
os._exit(0) # 使用os._exit确保立即退出
|
os._exit(0) # 使用os._exit确保立即退出
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user