欢迎来到代码驿站!

VBS

当前位置:首页 > 脚本语言 > VBS

VBScript 监控并结束指定进程的代码

时间:2022-10-11 12:12:27|栏目:VBS|点击:
运行效果图:



代码(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 AD日志开启脚本nableKerbLog的脚本

栏    目:VBS

下一篇:没有了

本文标题:VBScript 监控并结束指定进程的代码

本文地址:http://www.codeinn.net/misctech/216081.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有