Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use VBS to create and delete monitoring process

Shulou Source: shulou.com Published: 2022-06-03 20:02:34 11月12日 Update

This article mainly explains "how to use VBS to achieve monitoring process creation and deletion", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use VBS to achieve monitoring process creation and deletion" bar!

Monitor the creation of a process, and the temporary event consumer issues an alarm each time a new process is created.

1. Monitoring the creation of a process

The copy code is as follows:

StrComputer = "."

Set objWMIService = GetObject ("winmgmts:" _

& "{impersonationLevel=impersonate}!\" & strComputer & "\ root\ cimv2")

Set colMonitoredProcesses = objWMIService. _

ExecNotificationQuery ("select * from _ _ instancecreationevent" _

& "within 1 where TargetInstance isa 'Win32_Process'")

I = 0

Do While i = 0

Set objLatestProcess = colMonitoredProcesses.NextEvent

Wscript.Echo objLatestProcess.TargetInstance.Name

Loop

two。 Monitor the deletion of a process, and the temporary event consumer issues an alarm each time the process terminates.

The copy code is as follows:

StrComputer = "."

Set objWMIService = GetObject ("winmgmts:" _

& "{impersonationLevel=impersonate}!\" & strComputer & "\ root\ cimv2")

Set colMonitoredProcesses = objWMIService. _

ExecNotificationQuery ("select * from _ _ instancedeletionevent" _

& "within 1 where TargetInstance isa 'Win32_Process'")

I = 0

Do While i = 0

Set objLatestProcess = colMonitoredProcesses.NextEvent

Wscript.Echo objLatestProcess.TargetInstance.Name

Loop

3. Monitor the use of processors by processes

The copy code is as follows:

StrComputer = "."

Set objWMIService = GetObject ("winmgmts:" _

& "{impersonationLevel=impersonate}!\" & strComputer & "\ root\ cimv2")

Set colProcesses = objWMIService.ExecQuery _

("Select * from Win32_process")

For Each objProcess in colProcesses

SngProcessTime = (CSng (objProcess.KernelModeTime) + _

CSng (objProcess.UserModeTime)) / 10000000

Wscript

Thank you for your reading, the above is "how to use VBS to achieve monitoring process creation and deletion" content, after the study of this article, I believe you have a deeper understanding of how to use VBS to achieve monitoring process creation and deletion of this problem, the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Processes monitoring code learning events content situations programs alerts consumption processors that is ideas articles more knowledge knowledge points articles follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn MariaDB NVidia Shulou Tech Info