Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VBScript monitors and terminates a specified process

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report