VBScript 监控并结束指定进程的代码
代码(monprocess.vbs):
on error resume next
strcomputer = "."
arrtargetprocs = array("calc.exe", "notepad.exe", "other.exe")
'数组里为要监视的进程名
set sink = wscript.createobject("wbemscripting.swbemsink","sink_")
set objwmiservice = getobject("winmgmts:" & _
"{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
objwmiservice.execnotificationqueryasync sink, _
"select * from __instancecreationevent within 1 " & _
"where targetinstance isa 'win32_process'"
wscript.echo "are monitoring processes ..."
do
wscript.sleep 1000
loop
'***************************************************************************
sub sink_onobjectready(objlatestevent, objasynccontext)
'trap asynchronous events.
for each strtargetproc in arrtargetprocs
if lcase(objlatestevent.targetinstance.name) = lcase(strtargetproc) then
intreturn = objlatestevent.targetinstance.terminate
if intreturn = 0 then
wscript.echo "time: " & now & ", succeed!" & chr(9) & _
"name: " & objlatestevent.targetinstance.name
else
wscript.echo "time: " & now & ", failed!" & chr(9) & _
"name: " & objlatestevent.targetinstance.name
end if
end if
next
end sub
原文:https://www.enun.net/?p=2385
下一篇: VBS 加解密 For CAPICOM