Windows Service

Posted on 2012-09-19
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

    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

    You mean a batch file?
    LVL 43

    Assisted Solution

    by:Steve Knight
    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
    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

    Thanks guys for the advice and the praticle commands

    Featured Post

    Free book by J.Peter Bruzzese, Microsoft MVP

    Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

    Join & Write a Comment

    Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
    This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now