监控windows进程内存,超过一定阀值就杀死他重启进程

上一篇 / 下一篇  2015-12-25 10:00:40 / 个人分类:软件测试


m lR2Q~gf OQ:?6T0
Dim memory
Dim targetMemory 
Dim log,CurrentTime,Currentdate,data,sign
51Testing软件测试网 }es1~2L#~%]:s
Set   objArgs   =   WScript.Arguments  
if objArgs.Count < 3 then
WScript.Echo "请输入需要监控的进程名和内存大小(M)共3个参数: 程序名,内存大小,程序路径。"
WScript.Echo "在cmd调用 如:monitor.vbs notepad.exe 1 'C:\Program Files\'"
WScript.Quit
end if
processName=objArgs(0)
targetMemory=Cint(objArgs(1))
exePath=objArgs(2)&objArgs(0)
'Wscript.Echo exePath
'targetMemory = 1000 '设定内存判断预设值
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
51Testing软件测试网k%{n l6e_+d-V3X
Set bjshell=createobject("wscript.shell")

:h.T` `e9lF*_!mK5i0
log=objArgs(2)&"log.log"
'log="d:\log.log"
set fso=wscript.createobject("scripting.filesystemobject")

a|YwhCh wl0
if fso.fileexists(log) then
else
set f=fso.createtextfile(log)
end if 
51Testing软件测试网(v v(`6`'E*hFH
set fs =createobject("scripting.filesystemobject")
set fi =fs.opentextfile(log,8)
sign=0
Do while 1 
Set wmiObjects = wmiService.ExecQuery("SELECT * FROM Win32_process where caption='"&processName&"'")
if wmiObjects.count = 0 then
'msgbox "process not exist"
 if sign = 1 then
    objShell.Run Chr(34)&exePath&Chr(34)
    CurrentTime=Hour(Now)&":"&Minute(Now)&":"&Second(Now)
    Currentdate=date()
    data=Currentdate&" "&CurrentTime&" 启动程序!"
    'msgbox data
         fi.writeline data
sign =0
 end if
Wscript.Sleep 15000
else
For Each wmiObject In wmiObjects
memory = wmiObject.workingsetsize/1024/1024
if memory > targetMemory then
   'msgbox wmiObject.name&" 使用的内存: "& memory &"M" &  chr(10)
wmiObject.Terminate()
sign=1
Wscript.Sleep 6000
exit For
end if
next
End if
Loop

"t/LNv%z0
51Testing软件测试网'ZUEX/z!D'E
51Testing软件测试网l,c&U$Dy?"D&G

TAG: Windows 监控 windows

 

评分:0

我来说两句

Open Toolbar