'************************************************************************* '* '* Check if Process is Running: '* Check to see if 1 instance is running for a particular process '* '* Parameters: ProcessName '* '************************************************************************* Option Explicit Const PROCESS_NAME = "ProcessName" Const ALERT_SUCCESS = 10 Const ALERT_INFORMATION = 20 Const ALERT_WARNING = 30 Const ALERT_ERROR = 40 Const ALERT_CRITICAL_ERROR = 50 Const ALERT_SECURITY_BREACH = 60 Const ALERT_SERVICE_UNAVAILABLE = 70 Const ALERT_DESCRIPTION0 = "Process is NOT currently running. Please investigate." Const ALERT_DESCRIPTION1 = "More than one instance of the process is currently running. Please investigate." Const ALERT_NAME = "Process Check" Const ALERT_SOURCE = "Process Check Script" Const EVENT_TYPE_SUCCESS = 0 Const EVENT_TYPE_ERROR = 1 Const EVENT_TYPE_WARNING = 2 Const EVENT_TYPE_INFORMATION = 4 Const EVENT_TYPE_AUDITSUCCESS = 8 Const EVENT_TYPE_AUDITFAILURE = 16 Dim strProcessName Dim InstancesRunning Dim intCount Dim Instance intCount = 0 strProcessName = ScriptContext.Parameters.Get(PROCESS_NAME) Set InstancesRunning = getobject("winmgmts:").execquery("select * from win32_process where name = '" & strProcessName & "'") If InstancesRunning.count = 0 Then Dim oAlert Set oAlert = ScriptContext.CreateAlert() With oAlert .AlertLevel = ALERT_CRITICAL_ERROR .Description = ALERT_DESCRIPTION0 .Name = ALERT_NAME .AlertSource = ALERT_SOURCE End With ScriptContext.Submit oAlert ElseIf InstancesRunning.count > 1 Then Set oAlert = ScriptContext.CreateAlert() With oAlert .AlertLevel = ALERT_WARNING .Description = ALERT_DESCRIPTION1 .Name = ALERT_NAME .AlertSource = ALERT_SOURCE End With ScriptContext.Submit oAlert Else Dim oEvent Dim sMessage sMessage = "One Instance of " & strProcessName & " is running." Set oEvent = ScriptContext.CreateEvent() With oEvent .EventNumber = 40000 .EventType = EVENT_TYPE_SUCCESS .Message = sMessage .EventSource = "Check Process Script" End With ScriptContext.Submit oAlert End If Set InstancesRunning = Nothing