Get the App
SLTechnology News&Howtos  ›  Development  › 

How VBScript monitors and terminates a specified process

Shulou Source: shulou.com Published: 2022-06-03 07:48:22 10月04日 Update

This article mainly shows you "how VBScript monitors and ends the specified process". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how VBScript monitors and ends the specified process".

Run the effect diagram:

Code (monprocess.vbs):

The copy code is as follows:

On Error Resume Next

StrComputer = "."

ArrTargetProcs = Array ("calc.exe", "notepad.exe", "other.exe")

'The name of the process to be monitored in the array

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

The above is all the contents of the article "how VBScript monitors and ends the specified process". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Process monitoring code content articles learning help effects effect diagrams arrays easy to understand more organization knowledge editing industry information information channels channels monitoring Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux vpn Redmi Xiaomi