zl程序教程

您现在的位置是:首页 >  系统

当前栏目

windows 之 bat 实现进程守护

Windows进程 实现 bat 守护
2023-06-13 09:17:02 时间

参考信息:

windows下批处理实现进程监测 http://blog.51cto.com/10942560/2096009

.bat批处理命令常用操作 https://blog.csdn.net/zhanglu_1024/article/details/79595008

进程守护: protect_my_process.bat,文件保存编码为 ANSIC 码

@echo off

:RESTART

REM cd 到程序的目录下,防止其他问题出现

cd /d E:

cd /d E:\yinzhuoqun\

REM 查找要运行软件进程名称是否存在

tasklist /nh|find /i "my_process.exe"

REM 有则啥事不干,没有则启动该程序

If ERRORLEVEL 1 (start E:\yinzhuoqun\my_process.exe) else (echo 程序已运行)

REM 延时 10 * 2000 = 20s

ping -n 10 -w 2000 127.0.0.1 > tblm_temp.txt

REM 重新启动

goto RESTART

隐藏 bat 脚本启动的 CMD 窗口: hide_cmd_window.vbs

CreateObject("WScript.shell").Run"cmd /c E:\yinzhuoqun\protect_my_process.bat",0

CreateObject("C:\Windows\System32\wscript.exe").Run"cmd /c E:\yinzhuoqun\protect_my_process.bat",0

windows 开机自启的启动目录

vbs、bat 脚本以及 快捷方式 放入自启动目录,开机便会自动启动

C:\Users\{你的用户名}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

说明

python 脚本可以用 pyinstaller 打包成 exe,然后使用以上方法实现进程守护。