当前位置: 代码网 > it编程>前端脚本>其它脚本 > 使用vbs脚本来监控windows服务器上的应用程序(不存在就启动)

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

2024年05月15日 其它脚本 我要评论
这个vbs代码主要实现的功能就是运行该程序,就会在进程中出现一个wscript.exe 它会每隔10s扫面一次进程中是否存在notepad.exe这个程序,不存在就启动。这个启动程序可能跟进程名不一样

这个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系统运行后,系统进程中产生大量wscript.exe

taskkill /im wscript.exe /f
taskkill /im cscript.exe /f
taskkill /im consent.exe /f
taskkill /im chsime.exe /f

所有建议服务器上运行vbs后,如果出现大量wscript.exe进程,可以加上下面的命令

dim wshshell 
set wshshell = wscript.createobject("wscript.shell") 
wshshell.run "taskkill /im wscript.exe /f ",0 ,true

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

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com