February 22, 2023 at 7:44 pm
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 ?
February 22, 2023 at 9:19 pm
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
February 23, 2023 at 11:21 am
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
February 23, 2023 at 2:08 pm
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
February 23, 2023 at 5:13 pm
Does it trigger when you start the service and terminate it using taskmanager?
February 23, 2023 at 6:15 pm
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.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy