Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created 2 simple basic tasks in Task Schedule, one for Start and another for Stop a WinService at certain times on Daily basis. Now, I want to have the script somehow more comprehensive, e.g. like that:
Start: Monday-Friday, 5 AM
       Sat+Sunday, 7 AM
Stop:  Monday-Thursday & Sunday: 12 AM
       Friday, Sat.: 3 AM

How to script these in one or two .bat file(s)? Thanks.
Posted

1 solution

Learn command-line interface of the Windows Task Scheduler: http://en.wikipedia.org/wiki/Windows_Task_Scheduler[^].

For v.1.0, at.exe can be used (deprecated), for v.2.0, schtasks.exe. The syntax can be found here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx[^].

See also: http://technet.microsoft.com/en-us/magazine/ff356867.aspx[^].

—SA
 
Share this answer
 
Comments
s yu 25-Aug-14 13:57pm    
SA: Thanks for the valuable references. I want to stop the service on Sat & Sunday at 03:00am. I am not sure the format of the script. Could you have a brief look on the simple script below? Thanks.
@ECHO OFF
ECHO Starting service!
SC STOP WinService4Trains SAT, SUN /ST 03:00:00
Sergey Alexandrovich Kryukov 25-Aug-14 14:22pm    
The format is explained in on the page I referenced.
—SA
s yu 25-Aug-14 15:08pm    
I reset the Task Scheduler and used the Trigger: Weekly to eliminate days setup in the the script. Thanks.
Sergey Alexandrovich Kryukov 25-Aug-14 15:17pm    
Great. Good luck, call again.
—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