mlR2Q~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