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

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


g bi+M,J yf(w.P0
Dim memory
Dim targetMemory 
Dim log,CurrentTime,Currentdate,data,sign
51Testing软件测试网;H%g jk,pR
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")

E$U5ifAUw8W!l.q0
Set bjshell=createobject("wscript.shell")

.G2H5])@Yj9erF0
log=objArgs(2)&"log.log"
'log="d:\log.log"
set fso=wscript.createobject("scripting.filesystemobject")
51Testing软件测试网3b2q7W^s3j Gjq
if fso.fileexists(log) then
else
set f=fso.createtextfile(log)
end if 

!eDS9`9D'M/Z0
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
51Testing软件测试网6sD-IukZiYL&N

6N*W S{}"p|)bG0

v%i/bh"P2D7~0

TAG: Windows 监控 windows

 

评分:0

我来说两句

Open Toolbar