使用vbs脚本来监控windows服务器上的应用程序(不存在就启动)

2023-12-01 0 504

这个vbs代码主要实现的功能就是运行该程序,就会在进程中出现一个wscript.exe 它会每隔10s扫面一次进程中是否存在notepad.exe这个程序,不存在就启动。这个启动程序可能跟进程名不一样,好比tomcat应用,启动的是startup.bat,后台进程名为java.exe,这样就需要调整代码proname="java.exe"

关于如果关掉监控 可以在运行下执行taskkill /f /im wscript.exe 或者在任务管理器 进程中找到wscript.exe 结束进程就可以了

调整WshShell.Run("startup.bat")

核心代码

dim wmi,proc,procs,proname,flag,WshShell
Do
proname=\”notepadjb51.exe\” \’需要监测的服务进程的名称,自行替换这里的记事本进程名
set wmi=getobject(\”winmgmts:{impersonationlevel=impersonate}!\\.rootcimv2\”)
set procs=wmi.execquery(\”select * from win32_process\”)
flag=true
for each proc in procs
if strcomp(proc.name,proname)=0 then
flag=false
exit for
end if
next
set wmi=nothing
if flag then
Set WshShell = Wscript.CreateObject(\”Wscript.Shell\”)
WshShell.Run (\”notepadjb51.exe\”)
end if
wscript.sleep 10000 \’检测间隔时

VBS写个小脚本 实时监测指定程序是否运行 对运行的软件进行操作 最后关闭运行软件

strComputer = \”.\”
Set objShell = CreateObject(\”Wscript.Shell\”)
do
Set wbemServices = Getobject(\”winmgmts:\\\\\” & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf(\”Win32_process\”)
For Each wbemObject In wbemObjectSet
if wbemObject.name=\”QQ.exe\” then
WScript.Sleep 1000
objShell.SendKeys \”{F12}\”
WScript.Sleep 1000
objShell.SendKeys \”{ENTER}\”
dim WSHshell
set WSHshell = wscript.createobject(\”wscript.shell\”)
WSHshell.run \”taskkill /im wscript.exe /f \”,0 ,true
end if
Next
loop

批处理检测进程是否存在;这个我用来检测文化进程是否存在,因为是绿色版的,很容易被关闭,所以需要检测。

tasklist /nh|find /i \”ClientOfWatcher.exe\”
if ERRORLEVEL 1 (start C:\\watcher\\ClientOfWatcher.exe) else (exit)

VBS定时检测进程是否存在,如果不存在就启动进程。

option Explicit
dim wmi,proc,procs,proname,flag,WshShell
Do
proname=\”ClientOfWatcher.exe\” \’需要监测的服务进程的名称,自行替换这里的记事本进程名
set wmi=getobject(\”winmgmts:{impersonationlevel=impersonate}!\\\\.\\root\\cimv2\”)
set procs=wmi.execquery(\”select * from win32_process\”)
flag=true
for each proc in procs
if strcomp(proc.name,proname)=0 then
flag=false
exit for
end if
next
set wmi=nothing
if flag then
Set WshShell = Wscript.CreateObject(\”Wscript.Shell\”)
WshShell.Run (\”C:\\Watcher\\ClientOfWatcher.exe\”)
end if
wscript.sleep 50000 \’检测间隔时间,这里是50秒
loop

到此这篇关于使用vbs脚本来监控windows服务器上的应用程序(不存在就启动)的文章就介绍到这了,更多相关vbs守卫进程内容请搜索悠久资源网以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源网!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 VBS 使用vbs脚本来监控windows服务器上的应用程序(不存在就启动) https://www.u-9.cn/jiaoben/vbscript/9611.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务