Implement monitoring process creation and deletion code with VBS _VBS

Source: Internet
Author: User
Monitors the creation of a process, alerting the temporary event consumer every time a new process is created.

1. Monitoring the creation of processes
Copy Code code 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

2. Monitor the removal of the process, alerting the temporary event consumer every time the process terminates.

Copy Code code 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. Monitoring processes using the processor
Copy Code code 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

Reference Links:

    1. monitoring the creation of processes
    2. monitoring the removal of a process
Reference: Http://hi.baidu.com/%B1%F9%D0%C4%B3%D5/blog/item/5691a1c3146ded55b219a861.html http://demon.tw/programming/ Vbs-monitoring-process-creation-and-deletion.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.