Count number of instances

This script checks if notepad.exe is running more that 4 times. If it is running more than 4 times a event is generated. You can then collect those event and get an alert in operators console.


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Wscript.Shell")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")
If colProcesses.Count < 4 Then Const EVENT_WARNING = 2 Set objShell = CreateObject("Wscript.Shell") objShell.LogEvent EVENT_WARNING, _ "There are less then 4 instances of notepad.exe running" End If

One thought on “Count number of instances

Comments are closed.