Any ideas as to why the service running under a local service account can't execute the batch file? Thats exactly my thought as well. I think an external monitoring tool would be better for this, Total network monitor, nagios, etc. You could use a simple VB script on a scheduled task using WMI to check the status of the service, if it is not running restart the service in the script and fire the email so you are notified. I used to work with Microsoft SCOM at a previous job and it did all of this automagically but if you cant afford the cost of fancy monioring tools you can achieve much of this with simple scripts!
On one hand external tool is better, because preparing a task that fires at specific service termination is not trivial. You can actually setup e-mail notification in the advance feature of the event viewer if my memory serves me right.
Sureline Communications is an IT service provider. Try Zabbix or Op Manager, these can both monitor the service for you and can send you an email, they also have a dashboard with quick notifications which turn red when the service stops.
Is it possible that the account the service is running under doesn't have privileges to run the batch file you wrote? I was going to say what greenstarthree did. Anytime I run into the issue of "something works interactively, but when I schedule it, or [do something like make it part of Service event] , it doesn't work. Services run on Session 0 which is a special Windows session that doesn't support a desktop or user interaction. Does your script used Mapped drives?
Secured share drives? Anything where a resource could be denied because its running under a account you didn't think it was, or because that account was not able to establish a normal desktop and so something that would normally be there, is missing. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. Asked 9 years, 10 months ago. Active 6 years, 1 month ago. Viewed 7k times. Add emailAddresses ; mailMsg. Add emailCCAddresses ; mailMsg. ContentDisposition; disposition. Network; emailClient. WriteLine e. NetworkCredential "username","pwd","Domain1" ; changing the Log On As option of the service to be my userid and pwd The From and To email addresses are authentic, not dummy addresses in my real code that is! Improve this question. Some programmer dude k 33 33 gold badges silver badges bronze badges.
PreethaA PreethaA 12 12 silver badges 13 13 bronze badges. Do you have any firewall running? A quick Google for the message of the SocketException that's thrown initially "An attempt was made to access a socket in a way forbidden by its access permissions But i was able to send the smtp email via a console application same code, just not a service and via command prompt. Also, my coworker same team and access rights who ran the service on his windows xp machine was able to send email.
We checked with IT and they tell us we are not blocked. I would bet that it is the identity under which the service runs that is causing the issue. Once i installed the service, i changed the login to run as me, as opposed to the local system account If you are concerned that someone may have access to your script and discover your password then you will want to encrypt your credentials. Gmail requires and SSL connection so your password should be safe on the wire, just like any other email client.
Here is an example of a Powershell script that when used in conjunction with Task Scheduler which will send an email alert automatically when any specified Event is logged in the Windows Event Log. It then parses that event and assigns the EventID, Source, MachineName and Message to variables that will be used to compose the email.
From the XML view you can see all the data included with an event. Within there you will find additional Event Data stored as parameters. For my trigger you can start my setting up a trigger that monitors as I describe in my previous article.
In order to monitor for just the specific service we are interested in we will need to edit the XML directly as shown below. The default Condition parameters should be sufficient. Step 3 if necessary — Fix the Microsoft-Windows-DistributedCOM Event ID: Error In theory, if you did everything correctly you should now start receiving emails any time one of the events you are monitoring gets logged in the event log.
However, I ran into a weird permission issue on one of my servers that I had to address before everything worked. In my case when I manually triggered the event, or if I ran the Powershell script directly, everything worked as expected and I received an email. However, if one of the EventIDs being monitored was logged into the event log it would not result in an email being sent.
Many of the Google search results for that error indicate that the error is benign and include instructions on how to suppress the error instead of fixing it. However, I was pretty sure this error was the cause of my current failure to be able to send an email alert from a Scheduled Event that was triggered from a monitored Event Log entry, so I needed to fix it.
After much searching, I stumbled upon this newsgroup discussion. The response from Marc Whittlesey pointed me in the right direction. This is what he wrote….
I suggest you to follow some steps to fix issue:. Right click on it then select permission. Click Advance and change the owner to administrator. Also click the box that will appear below the owner line. Apply full control.
Click Advance and change the owner to administrators. Click the box that will appear below the owner line. Click Apply and grant full control to Administrators. Close all tabs and go to Administrative tool. Open component services. Look for the corresponding service that appears on the error viewer. Right click on it then click properties. Click security tab then click Add User, Add System then apply. Tick the Activate local box. I was able to follow Steps pretty much verbatim.
If you need to enable the same alerts on multiple systems you can simply export your Task to an XML file and Import it on your other systems. Or even better yet, automate the Import as part of your build process through a Powershell script after making your XML file available on a file share as shown in the following example. Hopefully what I have provided will give you everything you need to start receiving alert notification emails on whichever Windows Services keep you up at night.
This concludes my series on configuring email alerts.
0コメント