Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Windows Service

Posted on 2012-09-19
Medium Priority
Last Modified: 2012-09-19
Is it possible to have a windows service run only between certain hours...and at the end of the day do an automatic restart of the service?
Question by:lrbrister
LVL 23

Accepted Solution

Suliman Abu Kharroub earned 1000 total points
ID: 38413648
You can create a schedule taskes to start and stop the service:

Start: create a patch file to start a service (syntax: Net start service_name)

stop: create another file to stop the service ( Net Stop service_name).

create the tasks to call these files as needed..

Author Comment

ID: 38413658
You mean a batch file?
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 1000 total points
ID: 38413690
Beaten to it..... yes create a batch file or put the commands in the scheduled tasks, i.e. restart_service.cmd is

NET STOP "Service Name"
NET START "Service Name"

if you want a pause between for a few secs add a PING, e.g. this will stop, wait 20 secs hen start.

NET STOP "Service Name"
PING -n 20 >NUL
NET START "Service Name"

Obviously you can ge cleverer and check for whether the service stops right / starts right but depends how criticial the thing is.

LVL 18

Expert Comment

by:Sushil Sonawane
ID: 38413702
Create batch file and scheudle in task scheduler.

To start a service, type:
net startservice

To stop a service, type:
net stopservice

To pause a service, type:
net pauseservice

 To resume a service, type:
net continueservice


For Task Scheduler


Author Closing Comment

ID: 38413751
Thanks guys for the advice and the praticle commands

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question