Windows Server Alert When Service Doesn't Start - Not Working

  • I am trying to send an email when a Windows service doesn't start.

    What I did:

    I wrote a batch file that runs a short Powershell script to send an email. It works fine if I run the batch file by itself. I get an email.

    I have a service on my laptop set to "Automatic" startup, that I forced to "not start" by changing the password of the "Log On" account.

    On the "Recovery" Tab I set 1st and 2nd Failure tabs to "Run a Program"

    I checked "Enable actions for stops with errors"

    Under "Run Program" in the "Program" box, I browse to the BAT file and it shows: C:\My_TEST\SendMailMessage.bat

    I shut down and restart my laptop, but do not get an email when the service tries to start.

    Any Ideas ?

    • This topic was modified 1 year, 2 months ago by  homebrew01.
  • How are you sending the email?  What email service are you using - and what authentication method is required to access the mail server?

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Could it be it doesn't get triggered because it never started (due logon mismatch)? Can you test the actions without bat-file? Do they trigger?

    What's the security on the bat-file

    https://blog.stephencleary.com/2020/06/servicebase-gotcha-recovery-actions.html

  • Here's my powershell script (with company information changed)

    I'm "assuming" that since it works when I run the BAT file manually, which runs powershell, that it would use the same permissions when I reboot and log back in.....

    I didn't set any permissions on the BAT file or folder. Maybe it's too restrictive somehow ?

    param([string] $Param1 = "me@mycompany.com", [string] $Param2 = "Test_From_Services")
    $From = "My Company Notifications <xxxx@xxxxxx.com>"
    $To = $Param1
    $Subject = $Param2
    $Body = $Param2
    $SMTPServer = "mail.smtp2go.com"
    $Port = "2525"
    Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Port $Port
  • Does it trigger when you start the service and terminate it using taskmanager?

  • Jo Pattyn wrote:

    Does it trigger when you start the service and terminate it using taskmanager?

    Yes, those DO send the email.

    Maybe I misunderstood the functionality, and "Run a Program " activates only if an already running service stops running, not if a service fails to start in the first place, like after reboot.

    • This reply was modified 1 year, 2 months ago by  homebrew01.
    • This reply was modified 1 year, 2 months ago by  homebrew01.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply