Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule the start and stop of a Windows service?

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.

like image 949
Giacomo Tesio Avatar asked Feb 15 '23 11:02

Giacomo Tesio


2 Answers

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

like image 159
Moein Nourmohammadi Avatar answered Feb 18 '23 13:02

Moein Nourmohammadi


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."

like image 42
Rahul Tripathi Avatar answered Feb 18 '23 13:02

Rahul Tripathi