Schedule service stop/start automatically via script

Posted on 2007-10-18
Last Modified: 2013-12-23
I am in a siuation where I need to stop and start a windows service automatically and have been unable to come up with the exact script to do it. Here's the scenario:

I have a service we'll call Agent.exe that needs to run during off hours to peform a scan of the workstation in question. I have too many machines to do this as a scheduled task and would like to implement it via a login script for the user or a machine script for the workstation.

The script needs to stop the Agent service at 8 pm and start the service at 4 am with no user intervention.

I have tried the following in a batch file that is supposed to run at login:

at 8:00pm  net stop "Agent"
at 4:00am  net start "Agent"

If I run this as a .bat file locally on my workstation I have no problems. It executes as desired. However, the minute I plug it into a login it fails with no error warnings or messages.

Any ideas and thoughts are greatly appreciated.

Question by:boomer4d
    LVL 17

    Accepted Solution

    Use "Scheduled Tasks" to run the batch file according to a schedule.
    LVL 5

    Author Comment

    Unfortunately using "Scheduled Tasks" is not an option as all users are admins on their local machines (I know..........don't go there) and I can't stop them from dorking around with things like this. I meant to bring that up in my original post but forgot.............I don't multi-task as well as I used to.
    LVL 4

    Assisted Solution


    Use psexec for execute net start or net stop on every workstation at desired time and centralized mode.

    Command will be like this:

    psexec @workstation.txt -d -u adminuser -p adminpwd net start "agent"

    where workstaion.txt is a text file with names of target workstations .
    adminuser is adminuser and adminpwd is (obvious) the password.
    -d is used for no wait end of command and continue.


    Rememnber exclude this program (psexec)  in firewalls and antivirus.
    LVL 5

    Author Comment

    Thanks ya'll. Both answers could solve the issue. I ended up using a set of cmd files initiated by a batch file and run using a scheduled task from a local file server.

    I appreciate the help!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
    We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now