Windows 应用程序监控重启

执行思路 1.定时关闭可执行程序,2.再通过定时监控启动可执行程序

定时启动关闭程序.bat

csharp 复制代码
@echo off
cd "D:\xxxx\" :: 可执行程序目录
Start "" /b xxxx.exe  :: 可执行程序
timeout /T 600 /nobreak >nul :: 600秒
taskkill /IM xxxx.exe /F  :: 可执行程序关闭
exit

监控程序.bat

csharp 复制代码
@echo off
:run
:: 标题定义
title 监控程序
:: 当前路径
set strPath=%~dp0
:: 带绝对路径的文件名
set strFile=%strPath%%date:~0,4%%date:~5,2%%date:~8,2%.log
:: 输出时间到文件
echo [%time%] >>%strFile%
:: 输出计算器的进程信息到文件
:: tasklist -nh -fo csv -fi "IMAGENAME eq 定时启动关闭程序.bat" >>%strFile%
tasklist -fi "IMAGENAME eq 定时启动关闭程序.bat" >>%strFile%
:: 下面是检查进程是否存在,不存在启动当前路径下的脚本文件1.bat
tasklist|find /i "xxxx.exe"
if %errorlevel%==0 (
	echo 采集webapi程序已启动
) else (
	echo 采集webapi程序不存在,启动
	start  /d"D:/bat地址目录" 定时启动关闭程序.bat
)
:: 定时5秒
choice /t 5 /d y /n >nul
goto run
相关推荐
泡^泡4 分钟前
Python数据类型与运算符
开发语言·windows·python
caimouse12 小时前
Reactos 第 4 章 对象管理 — 4.5 几个常用的内核函数
c语言·windows·架构
caimouse12 小时前
Reactos 第 4 章 对象管理 — 4.3 句柄和句柄表(Handle & Handle Table)
c语言·windows·架构
Chase_______13 小时前
【Java基础 | 15】集合框架(中):Set、HashSet、TreeSet 与哈希表
java·windows·散列表
caimouse14 小时前
Windows NT 内核架构(主通用模型)流 NT 5.x/10+
windows·架构
caimouse14 小时前
Reactos 第 3 章 内存管理 — 【中篇】Hyperspace、系统空间、API 与异常
c语言·开发语言·windows·架构
caimouse15 小时前
Reactos 第 4 章 对象管理 — 4.1 对象与对象目录
服务器·c语言·开发语言·windows·架构
影寂ldy18 小时前
C# 索引器(Indexer)超全笔记【基础 + 重载 + 实战练习】
windows·microsoft
caimouse21 小时前
Reactos 第 4 章 对象管理 — 4.2 对象类型(Object Type)
c语言·windows·架构
caimouse21 小时前
Reactos 第 4 章 对象管理 — 4.4 对象的创建
windows·架构