Reputation: 7210
I've a .NET windows service that should start at 7:00 and stop at 23:00 each day, running continuously in background.
While I can code the service so that it sleep between 23 and 7, I would prefer a system configuration (something like cron in unix).
How can I do this on Windows 7?
Note that, if system boot up after 7:00, the service should start immediatly.
Upvotes: 6
Views: 30571
Reputation: 459
AT
command gets deprecated at some point. This works server 2012, Windows 10.
schtasks /create /tn "StartWrapper" /tr "NET START 'Name of Service'" /sc daily /st 23:05 /RL HIGHEST
You have to play with the quotes to escape the command correctly.
Upvotes: 0
Reputation: 128
1- Create a batch file such as starter.bat and type NET START "SERVICE NAME"
2- Create a Task in Task Scheduler for 7:00 a.m that run batch file every day and remember to check Run task as soon as possible after a scheduled start is missed in Settings tab so it will start even if system boot up after 7 a.m.
Repeat those steps for stoper.bat include NET STOP "SERVICE NAME" for 23:00 p.m
Upvotes: 7
Reputation: 20330
Seeing as you need another service to manage the scheduling of the services. Write a service, that hosts service like thingies. The host deals with starting and stopping, even restarting in the event of a crash. You can even get clever and get it to look up with "services" to load an run, and applet to see what's going on and tweak the schedule , register and unregister services with the host.
An approach anyway.
Upvotes: 0
Reputation: 7385
Or you could write another service, let's call it guard which runs always und starts the other service depending on a config file for example.
Upvotes: 0
Reputation: 172608
You could use Windows task scheduler for this task or a schedule task.
Also Windows AT command is very similar to Cron in Unix
"The AT command schedules commands and programs to run on a computer at a specified time and date. The Schedule service must be running to use the AT command."
Upvotes: 2