none
How to send email msg if a windows service stops?

Answers

All replies

  • Skoppula, I am infering you are talking about if a system service stops you want an email notification.  There are a couple routes you can take on this.

    1. You can write your own applet

    2. You can use some of the great MS products like SCCOM or MOM

    3. There are many 3rd party applications that are in the market that can offer a whole range of system events and information to alert on.

    Bing! for system moniroting and alerting

    Tuesday, July 19, 2011 5:52 PM
  • Hi Jason, thanks for repley.

    Any idea..about batch files/VBscripts for this.

    Tuesday, July 19, 2011 6:03 PM
  • To further elaborate Jason's recommendations...

    For a stand-alone system, the easiest method is to have the system "run a program" when the service fails.  You can set that configuration in the "Recovery" tab when accessing the properties of the service.  The program you will run will be most likely a vbscript.  This vbscript will send out the message.  YOu'll notice that in the recovery tab, when you select the action from the drop down of "first failure", other options are presented so you can "pipe" in information to your vbscript about the service.  So, you can have one script used for more than one service by sending the script information about the service that failed.  

    For a scenario where you want to monitor services for many systems, the MS product that does this is Operations Manager (MOM/SCOM).  Product used to be called MOM, Microsoft OPerations Manager, but is now referred to SCOM, Systems Center Operations Manager.

    More info on SCOM: http://www.microsoft.com/systemcenter/en/us/operations-manager.aspx.

     

     


    anITKB Visit anITKB.com, an IT Knowledge Base.
    facebook Follow me on Facebook.
    Tuesday, July 19, 2011 6:03 PM
  • Hi JM,

    Thanks alot for repley..

    Could you pl provide me VBscript for the same if you have..thank in advance.

    I need it for single machine and couple of services.

     


    Tuesday, July 19, 2011 6:11 PM
  • I have a sample one that you can use and modify to your needs.  Its a stand-alone script so it will need an adjustment to accept parameters if you want to reuse it for different services.

    Send an Email Message Using VBScript
    http://www.anitkb.com/2010/03/send-email-message-using-vbscript.html

    I also have an example on how to pass parameters to a vbscript.

    How to Pass Parameters to VBScript
    http://www.anitkb.com/2010/10/how-to-pass-parameters-to-vbscript.html

     

    Hope that helps...

     


    anITKB Visit anITKB.com, an IT Knowledge Base.
    facebook Follow me on Facebook.
    Tuesday, July 19, 2011 6:24 PM
  • In windows 2008, you can generate an email alert based on an event log or ID.   Review the following blog:

    http://portal.sivarajan.com/2010/04/generate-email-alert-to-event-attach.html


    Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA, Network+ Houston, TX

    Blogs - http://blogs.sivarajan.com/
    Articles - http://www.sivarajan.com/publications.html
    Twitter: @santhosh_sivara - http://twitter.com/santhosh_sivara
    This posting is provided AS IS with no warranties,and confers no rights.
    Tuesday, July 19, 2011 6:26 PM
  • As an example, here is a Powershell script that checks that the BITS service is running.  It does this every 60 seconds, and if it is not running, sends an email to the administrator:

     

    while ((Get-Service "BITS").status -eq "Running")
    {Start-Sleep -Seconds 60} 
    Send-MailMessage -From bits@ps.local -To admin@ps.local -Body "Bits Stopped" -SmtpServer server1
    

     Alternatively, you can put a .cmd file in your Recovery Tab of the service, as noted by JM, and use the following command:

    Powershell Send-MailMessage .....


    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".

    Tuesday, July 19, 2011 7:18 PM
  • Nicely done with powershell Bigteddy...

     


    anITKB Visit anITKB.com, an IT Knowledge Base.
    facebook Follow me on Facebook.
    Tuesday, July 19, 2011 7:43 PM
  • Very cool I never knew this.  Thanks for this post.  I will definitely use this feature.
    Dave - http://www.dms-itconsulting.com
    Wednesday, July 20, 2011 1:56 AM
  • Thanks, JM, it is rather cute, isn't it.  I LOVE Powershell!
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
    Wednesday, July 20, 2011 4:31 PM
  • As an example, here is a Powershell script that checks that the BITS service is running.  It does this every 60 seconds, and if it is not running, sends an email to the administrator:

    while ((Get-Service "BITS").status -eq "Running")
    {Start-Sleep -Seconds 60} 
    Send-MailMessage -From bits@ps.local -To admin@ps.local -Body "Bits Stopped" -SmtpServer server1
    

     Alternatively, you can put a .cmd file in your Recovery Tab of the service, as noted by JM, and use the following command:

    Powershell Send-MailMessage .....


    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".

    Bigteddy,  can you advise on how to make this run say, forever?  I ran it in Powershell Console, but after it sends the email one time, I'm back at a command prompt.


    TravisJ

    Friday, March 30, 2012 5:30 PM
  • Hello Travis and others,

    Thanks for your simple & easy script. As I understand through testing it, the script runs in a powershell window, until it finds the service is stopped. Then it sends an email and quits.

    What I would like to do, is the following:

    - start the script in the background (i.e. 'silent') when the server starts;

    - run the script without logging on;

    - keep the script running, even when it found that the service wasn't running (so the script shouldn't quit after sending the alert). As an alternative, it would be OK to, if the script somehow restarted after restarting the service.

    Would anybody know a way to get this to work?

    Kind regards,

    Marco Visser

    Wednesday, May 23, 2012 2:24 PM
  • Hello Travis and others,

    Thanks for your simple & easy script. As I understand through testing it, the script runs in a powershell window, until it finds the service is stopped. Then it sends an email and quits.

    What I would like to do, is the following:

    - start the script in the background (i.e. 'silent') when the server starts;

    - run the script without logging on;

    - keep the script running, even when it found that the service wasn't running (so the script shouldn't quit after sending the alert). As an alternative, it would be OK to, if the script somehow restarted after restarting the service.

    Would anybody know a way to get this to work?

    Kind regards,

    Marco Visser

    Must be a way to loop this. I am curious as well.
    • Proposed as answer by Steven_B_ Friday, April 28, 2017 8:36 AM
    Thursday, May 24, 2012 3:24 PM
  • Old thread, but you could use Task Manager to run the powershell script every so often.
    Friday, April 28, 2017 8:37 AM
  • I blogged about this today. In my step-by-step guide the email will be generated as soon as the specified service either starts or stops. You can check out the details here.

    https://clusteringformeremortals.com/2018/10/29/step-by-step-how-to-trigger-an-email-alert-when-a-windows-service-starts-or-stops-on-windows-server-2016/



    David A. Bermingham, MVP, Senior Technical Evangelist, SIOS Technology Corp

    Monday, October 29, 2018 10:48 PM