《用VBS实现监视进程创建与删除的代码》由会员分享,可在线阅读,更多相关《用VBS实现监视进程创建与删除的代码(1页珍藏版)》请在金锄头文库上搜索。
1、监视进程的创建,在每次创建新的进程时,临时事件消费程序都发出警报。1监视进程的创建代码如下:strComputer =.Set objWMIService = GetObject(wi nm gmts: _& impers on ati on Level=impers on ate! & strComputer & rootcimv2)Set colMo nitoredProcesses = objWMIService. _ExecNotificati on Query(select * from _in sta ncecreatio nevent _& wit
2、hin 1 where TargetI nsta nee isa Win 32_Process)i = 0Do While i = 0Set objLatestProcess = col MonitoredProcesses.NextEventWscript.Echo objLatestProcess.Targetl nsta nce.NameLoop2. 监视进程的删除,在每次进程终止时,临时事件消费程序都发出警报。代码如下:strComputer =.Set objWMIService = GetObject(wi nm gmts: _& impers on ati on Leve
3、l=impers on ate! & strComputer & rootcimv2)Set colMo nitoredProcesses = objWMIService. _ExecNotificati on Query(select * from _in sta ncedeleti on eve nt _& within 1 where TargetI nsta nee isa Win 32_Process)i = 0Do While i = 0Set objLatestProcess = col Mon itoredProcesses.NextEve ntWscr
4、ipt.Echo objLatestProcess.TargetI nsta nce.NameLoop3. 监视进程使用处理器的情况代码如下:strComputer =.Set objWMIService = GetObject(wi nm gmts: _& impers on ati on Level=impers on ate! & strComputer & rootcimv2)Set colProcesses = objWMIService.ExecQuery _(Select * from Win 32_process)For Each objProcess in colProcessessn gProcessTime = ( CSn g(objProcess.KernelModeTime) + _CSn g(objProcess.UserModeTime) / 10000000Wscript