'========================================================================== ' NAME: ProcessMon.vbs ' AUTHORS: Pete Zerger, System Center Forum ' ' DATE : 06/17/2008 ' COMMENT: 'This is script is designed for use in a 2-state monitor in Operations Manager 2007. Its function is to 'verify the desired number of instances of a given process are running on the target machine 'INSTRUCTIONS FOR USE: ' Set the script parameters mentioned below (process name and count). Set your target as "Windows Server OS" 'and set the monitor to DISABLED. Use overrides to enable for desired agent-managed computers. 'Script Parameters '================= 'strProcessName - Name of the process you wish to monitor for (e.g. "notepad.exe" 'intTargetProcessCount - the target number of running instance of the process targeted for monitoring. Default is 1. '------------------------------------------------- On Error Resume Next '================= 'Declare Constants '================= 'OpsMgr Event-related Constants Const EVENT_TYPE_ERROR = 1 Const EVENT_TYPE_WARNING = 2 Const EVENT_TYPE_INFORMATION = 4 Dim oAPI, oBag Set oAPI = CreateObject("MOM.ScriptAPI") Set oBag = oAPI.CreateTypedPropertyBag(StateDataType) strComputer = "." '============================================ '***IMPORTANT**** 'Set target process name and running instance count '============================================ 'Set target process name here strProcessName = "notepad.exe" 'Set number of instances of the process that should be running. intTargetProcessCount = 1 Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") If Err.number <> 0 Then 'Wscript.echo Err.Description Call oAPI.LogScriptEvent("ProcessMon.vbs",4005, EVENT_TYPE_ERROR , "WMI Call Failed") Call oBag.AddValue("State","BAD") Call oAPI.Return(oBag) Wscript.quit End If strQuery = "Select * from Win32_Process Where Name = '" & strProcessName & "'" Set colProcesses = objWMIService.ExecQuery (strQuery) 'If process count = 0, then set state to BAD If colProcesses.Count = 0 Then Call oBag.AddValue("State","BAD") Call oAPI.Return(oBag) Wscript.quit 'If process count = strTargetProcessCount, then set state to GOOD ElseIf colProcesses.Count = int(intTargetProcessCount) Then Call oBag.AddValue("State","GOOD") Call oAPI.Return(oBag) Wscript.quit 'If process count > strTargetProcessCount, then set state to BAD ElseIf colProcesses.Count > int(intTargetProcessCount) Then Call oBag.AddValue("State","BAD") Call oAPI.Return(oBag) Wscript.quit Else Call oBag.AddValue("State","BAD") Call oAPI.Return(oBag) Wscript.quit End If