通过批处理命令和计划任务实现程序的停止和监控重启动

来源:互联网 发布:网络借贷信息披露细则 编辑:程序博客网 时间:2024/06/06 03:38

以程序“test.exe”为例,目录位于“D:\test\test.exe”

一. 终止程序 stop.bat

@echo off
ntsd -c q -pn test.exe


二. 监控程序是否运行,如果未运行,启动该程序 monitor.bat

tasklist /nh|find /i "test.exe"
if ERRORLEVEL 1 (start D:\test\test.exe) else (echo 程序已运行 exit)


三.有时候我们要监控的外部程序启动时会加载很多的配置或DLL,这时候采用上面的办法就会发现,这些配置都没有加载上去,因为exe的运行环境不对,可以采用下面的办法

tasklist /nh|find /i "test.exe"
if ERRORLEVEL 1 (pushd  D:\test
start test.exe

else (echo 程序已运行 exit)


建立计划任务后,可以通过高级属性使监控任务monitor.bat每隔一段时间重复执行。

0 0