[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7446
  • Last Modified:

Schedule service stop/start automatically via script

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.

TIA!
0
boomer4d
Asked:
boomer4d
  • 2
2 Solutions
 
2PiFLCommented:
Use "Scheduled Tasks" to run the batch file according to a schedule.
0
 
boomer4dAuthor Commented:
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.
0
 
jordibartrinaCommented:
Hello,

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.

HTH

Rememnber exclude this program (psexec)  in firewalls and antivirus.
0
 
boomer4dAuthor Commented:
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!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now