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

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


]i*e;ena0
Dim memory
Dim targetMemory 
Dim log,CurrentTime,Currentdate,data,sign

!M]&[.?qqT;s:F0
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")

S&e6j4IK(]2e0
Set bjshell=createobject("wscript.shell")
51Testing软件测试网.j q)G},L D HW/E^8P:`
log=objArgs(2)&"log.log"
'log="d:\log.log"
set fso=wscript.createobject("scripting.filesystemobject")
51Testing软件测试网0T y"a Y!NN+Edr2m
if fso.fileexists(log) then
else
set f=fso.createtextfile(log)
end if 
51Testing软件测试网;v9FR"F6U6`F
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

ve-}8S2P@0

2nDi8^7Ww5ml{0

+~ m0N-a'cU+t0

TAG: Windows 监控 windows

 

评分:0

我来说两句

Open Toolbar