您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“VBScript如何監控并結束指定進程”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“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
以上是“VBScript如何監控并結束指定進程”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。