script or program that can notify me if a process stops working

Dan
Dan used Ask the Experts™
on
I am using windows xp and I wanted to know if there's a simple script I can write, or a program I download that can notify me if a process stops for any reason?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
This will give you the status of a service, just change the line strServiceName


Set objComputer = GetObject("WinNT://computername,computer")objComputer.Filter = Array("Service")
strServiceName = "blaablaa"
For Each aService In objComputer  
If LCase(strServiceName) = LCase(aService.Name) Then      
Wscript.Echo aService.Name & "=" & aService.Status   End IfNext
DanNetwork Engineer

Author

Commented:
actually, it's not a service that I'm looking for, but it's a process.  
Commented:
I found something like this which may work for you:
tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="1" echo Handle it however you would like

It's from a thread here:
http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

DanNetwork Engineer

Author

Commented:
thanks, so thats how to check if the process is running, but how do I get it to email me if it's not running?
DanNetwork Engineer

Author

Commented:
I tried it, but it actually doesn't work for me, I wonder what I'm doing wrong?
Commented:
Try this script.   Follow the comments and make the changes to point to your server and username and password


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

strComputer = "." '* This computer

'* Change the following line to the process you wnt to check on
strProcess = "notepad.exe"
Set wbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set wbemServices = wbemLocator.ConnectServer(strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process")

BoolFound = False
For Each wbemObject In wbemObjectSet
      If LCase(wbemObject.Name) = strProcess Then
            wscript.echo "notepad is running"
            boolFound = True
      End If

Next
'* You can change the below variables to adapt for your usage.
WScript.Echo "BoolFound is " & BoolFound
If BoolFound = False Then
      Set objMessage = CreateObject("CDO.Message")
      objMessage.Subject = "The process is not running"
      
      '* Change the following to your mail server
      objMessage.From = """afacts"" <afacts@server.com>"
      objMessage.To = "afacts@server.com"
      '* Change the following to your message
      objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."
      
      '==This section provides the configuration information for the remote SMTP server.
      
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      
      'Name or IP of Remote SMTP Server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.comcast.net"
      
      'Type of authentication, NONE, Basic (Base64 encoded), NTLM
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
      
      'Your UserID on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "UserName"
      
      'Your password on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"
      
      'Server port (typically 25)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      
      'Use SSL for the connection (False or True)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
      
      'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      
      objMessage.Configuration.Fields.Update
      
      '==End remote SMTP server configuration section==
      Err.Clear
      
      objMessage.Send
 
End If

Commented:
You get a chance to try the script above?   Just copy the script into a file and name it with a .vbs extension.   Like EmailProcess.vbs or similar.   You can us the AT command to schedule it to run every hour, or every 15 minutes.

Scott

Commented:
Don't forget to make the edits for the email server, username, and password.
DanNetwork Engineer

Author

Commented:
How do I execute or start the script, since it's a .vbs, is it like a .bat?  How do I start it, because I would want this script to run continously, right, how do I do that?

Commented:
To test it, open a command promt.  If you saved it in c:\scripts you would type cd scripts to change to the  scripts driectory, and then type EmailProcessEnding.vbs (or whatever you named it).

I'v modified to run continuously, and check every 15 minutes.

I've attached the modified script file.

Doln't forget to edit the email settings.
EmailProcessEnding.vbs
DanNetwork Engineer

Author

Commented:
can you resave the file as .txt, as my firewall blocks .vbs files

Commented:
attached EmailPreocessEnding.txt
EmailProcessEnding.txt
DanNetwork Engineer

Author

Commented:
ok, this is good, I went to a cmd prompt and ran the script after making the changes and I received the 2 messages and then I received the email, so that part works, but how do i get it to always just run in the banground when the computer starts up?  And also, I want it to check ever 3 minutes, not every 15, what changes do I need to do?

Commented:
Create a shortcut in start\programs\startup to make it run on start up.    3 mins is 3x60x1000=180000 milliseconds.

Commented:
the 180000 is at the bottom:
WScript.Sleep 180000
DanNetwork Engineer

Author

Commented:
can I use the task scheduler to start on startup, as that's the same thing, right?
DanNetwork Engineer

Author

Commented:
3 x 60 = 18000, it doesn't equal 180000
So do I use 18000, or 180000?

Commented:
3 times 60 = 180
180 x 1,000 = 180,000
180000.   WSCript.Sleep uses milliseconds, 1\1000th of a second.

I have written a custom vbscript for you that monitors a process and emails you if it stops, and have modified it to your specifications.   It is time to close and grade this issue.  



DanNetwork Engineer

Author

Commented:


This is the error message I'm getting.  How do I fix this?
vbs.jpg

Commented:
Redownload the working copy I posted here and edit JUST the WScriptSleep line at the body, and the items specific to your mail server.   You had it working yesterday, so just start with the posted file posted here.
DanNetwork Engineer

Author

Commented:
I'll do that, but that was on my computer, but I need it to run on a different computer. But I'll redownload hte file and change what needs to be changed.

Commented:
Dont forget to accept the solution.
DanNetwork Engineer

Author

Commented:
don't worry, I won't forget to accept the solution.

It's email me, so that part works, but the part that does not work is when it checks if the process is running and even though the process is running, it's saying it's not running.  So it's not working.
Here's what I have.


boolTest = False
Do While boolTest = false

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

strComputer = "." '* This computer

'* Change the following line to the process you want to check on
strProcess = "FMLECmd.exe"
Set wbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set wbemServices = wbemLocator.ConnectServer(strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process")

BoolFound = False
For Each wbemObject In wbemObjectSet
      If LCase(wbemObject.Name) = strProcess Then
            wscript.echo "FMLECmd is running"
            boolFound = True
      End If

Next
'* You can change the below variables to adapt for your usage.
WScript.Echo "BoolFound is " & BoolFound
If BoolFound = False Then
      Set objMessage = CreateObject("CDO.Message")
      objMessage.Subject = "The process is not running"
     
      '* Change the following to your mail server
      objMessage.From = """streampc"" <netadmin@xxxxxxxxx.org>"
      objMessage.To = "dandries@xxxxxxxxxx.org"
      '* Change the following to your message
      objMessage.TextBody = "The FMLEcmd process is not running..." & vbCRLF & "It was sent using SMTP authentication."
     
      '==This section provides the configuration information for the remote SMTP server.
     
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     
      'Name or IP of Remote SMTP Server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.xxxxxxxx.org"
     
      'Type of authentication, NONE, Basic (Base64 encoded), NTLM
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     
      'Your UserID on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxx"
     
      'Your password on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxxx"
     
      'Server port (typically 25)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
     
      'Use SSL for the connection (False or True)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
     
      'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
      objMessage.Configuration.Fields.Update
     
      '==End remote SMTP server configuration section==
      Err.Clear
     
      objMessage.Send
 
End If

'* Sleep for 3 minutes
'* Time is in milliseconds 3min x 60 sec x1000 milliseconds
WSCript.Sleep 18000

Loop

Commented:
change it to notepad.exe and test it with notepad open and closed.

That worked for me.  Also try putting a single quote '  at the beginning of live 5 cdoSendUsingPickup
DanNetwork Engineer

Author

Commented:
It works with notepad, but it doesn't work with the FMLECmd.exe process that is running.
Actually, I don't know if it makes a difference, but I have 2 FMLECmd.exe processes running all the time, could that make a difference?  Is there a way for the program to make sure and check if both processes are running?

Commented:
Try it with a single process running abd see if it works.

I'm not going to try to make it work with 2 processes.   If it was my job yes, but as it is not, I've spent enough time on this one and have done 99% of the job for you.  You are on your own from here.
DanNetwork Engineer

Author

Commented:
sgdought,  thanks again for your help, like I said, I don't code, I don't know vbscript, so I would love to write my own script, I just don't know how.

I was thinking, if it's easier, instead of having the script email me if it doesn't work, can you change it to just have it start the following program with the following parameters? That's after the script would check to see if both of the FMLECmd.exe processes are running or not?

CD \Program Files\Adobe\Flash Media Live Encoder 3.1>
fmlecmd /p c:\aftv\aftv.xml /ap xxxxxx:xxxxxx /t 01:02:00 /l c:\aftv\aftv.txt /r
fmlecmd /p c:\aftv\mobile.xml /ap xxxx:xxxxx /t 01:02:00 /l c:\aftv\mobile.txt /r
DanNetwork Engineer

Author

Commented:
Thanks for your help, I tried it, but it didn't work.
Either way, I found a paid cheap solution.

www.streamalerts.com

You can monitor as many streams as you want and they do have a free service, or paid, depending on what you want.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial