Search This Blog

Tuesday, April 26, 2011

Running a batch file from Service Recovery

We had an issue with a third party program that every now and again would suddenly fail. It was running as a service, now we wanted to be alerted to this so I thought I could just include a previously written batch file (slightly modified for the new purpose) in the service recovery “Run a program” section and have it alert us using email.

However I soon discovered that running a batch file from the “Run a Program” option in the service recovery tab does not work.

See here…. (This behaviour is by design…. Smile super…)

http://support.microsoft.com/kb/247929

Anyway so I thought, no worries I will use the work around forcedos…. However there is a character limit on the command, which pretty much rules this out for my purpose.

FORCEDOS: Command line too long
The command line cannot be longer than 125 characters.

So I struggled to see how I was going to get round this….

Then I thought about “scheduled tasks”… and this is how I solved the problem. The batch file is setup to run as a scheduled task with no schedule.

Then in the Service Recovery tab for the service, the program is set to

“schtasks”

and the command line parameters set to

“/RUN /TN "<taskname>"”

This now works a treat… A pain but I think a nice work around, as most of the other batch files I have are scheduled in the scheduled task manager the finished work around actually fits in quite nicely.


Share/Bookmark

No comments:

Post a Comment