[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转贴] VBS脚本实现监视进程创建与删除

监视进程的创建,在每次创建新的进程时,临时事件消费程序都发出警报。

1.监视进程的创建
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  4. Set colMonitoredProcesses = objWMIService. _
  5. ExecNotificationQuery("select * from __instancecreationevent " _
  6. & " within 1 where TargetInstance isa 'Win32_Process'")
  7. i = 0
  8. Do While i = 0
  9. Set objLatestProcess = colMonitoredProcesses.NextEvent
  10. Wscript.Echo objLatestProcess.TargetInstance.Name
  11. Loop
复制代码
2.监视进程的删除,在每次进程终止时,临时事件消费程序都发出警报。
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  4. Set colMonitoredProcesses = objWMIService. _
  5. ExecNotificationQuery("select * from __instancedeletionevent " _
  6. & "within 1 where TargetInstance isa 'Win32_Process'")
  7. i = 0
  8. Do While i = 0
  9. Set objLatestProcess = colMonitoredProcesses.NextEvent
  10. Wscript.Echo objLatestProcess.TargetInstance.Name
  11. Loop
复制代码
3.监视进程使用处理器的情况
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  4. Set colProcesses = objWMIService.ExecQuery _
  5. ("Select * from Win32_process")
  6. For Each objProcess in colProcesses
  7. sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
  8. CSng(objProcess.UserModeTime)) / 10000000
  9. Wscript
复制代码

转载连个出处都没有。

TOP

返回列表