Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I created a WinService and set up its start and stop on Scheduled Tasks. But everyday after the service is started for about 20 seconds, it automatically stops without any alert even though in Scheduled Task I did setup re-starting if starting fails. Therefore, I have to re-start the service manually everyday morning. Now, I want to write a batch file that can implement the following tasks:
1) Check where the WinService is running
2) If not in 1), start the service
3) Write the record for 1) and 2).
I did read a couple posted threads from websites, but I have not found one one that provides a good procedure to follow up. If you can share your experience on it, it will be greatly appreciated.
Posted

1 solution

You don't need to write such batch file. Instead, you need to fix your service. You can set up your service for auto-start each time Windows is loaded. You should never be in the need to manually start a service. Even if you write this batch file, it won't help you, because you service is not working properly; this is apparent from your description.

What you are trying to do would be the abuse of technology above any reasonable scale.

—SA
 
Share this answer
 
v2
Comments
s yu 23-Sep-14 7:46am    
SA: Thanks for your rsponse. I did setup auto-start for my service. In my program, there are lines of code to track the service's start and stop status. But there was no stop record in my log file. It appears that the problem migh not due to the service itself. Yesterday, I used a .bat fille to check the status of my service. If it is stopped, it will statr the service again. From this morning's observation, this approach works. I will continue to monitor for days. By the way, I could not understand your word: What you are trying to do would be the abuse of technology above any reasonable scale. Thanks again
Sergey Alexandrovich Kryukov 23-Sep-14 10:56am    
Well, if I understand your post correctly, you don't know why your service stops in 20 seconds. I have no information on its code, so I don't know easily. But apparently, if this is so, you just have some bug. Instead of fixing it, you are trying to work around it on the level of the usage. How can it be anything but abuse.

Sorry if I miss something; in this case, please clarify.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900