Skip to end of metadata
Go to start of metadata

Introduction

Restarting a Windows Service at a particular time is demonstrated in this article with two jobs that respectively stop and start the Windows Update Service.
The Windows Update Service is used in this example as it is neither system-critical (in the short term) and can be stopped and started by a single command without further input.
It is assumed that JobScheduler running these jobs is configured to run as a service.

The first job service_stop stops the service and the second job service_start starts it.
Both jobs use the Windows net.exe application.
This program can be found in the Windows system32 subdirectory.
To specify the program path you can use the %windir% environment variable.

Note that as presented here the jobs will work on Windows XP systems.
On Vista and Windows 7/8 it is necessary to ensure that JobScheduler is running under a user account with the necessary administrative permissions to start and stop services. It is also necessary that the JobScheduler service is configured to automatically register itself under this user account.
JobScheduler runs by default under the "local system" account on Windows systems, without these permissions. We recommend that JobScheduler is run under another user account with permission to start and stop services.
Note that this will mean that locations where, for example, temporary JobScheduler files are saved will change to this new user's file area.

Stop a Windows service

Paste the following code into a file ./config/live/service_stop.job.xml:

 <?xml version="1.0" encoding="iso-8859-1"?>
 <job>
   <script language="shell"><![CDATA[ 
     %windir%\system32\net.exe stop wuauserv
   ]]></script>
   <run_time>
     <period single_start = "03:00"/&gt;
   </run_time>
 </job>

Start a Windows service

Paste the following code into a file ./config/live/service_start.job.xml:

 <?xml version="1.0" encoding="iso-8859-1"?>
 <job>
   <script language="shell"><![CDATA[ 
     %windir%\system32\net.exe start wuauserv
   ]]></script>
   <run_time>
     <period single_start = "03:02"/>
   </run_time>
 </job>

Instead of using a delay of several minutes in the hope that the first job has been completed before the second starts, we recommend that a third script is used to start
the second job after the first job, should the first one complete successfully.
You could configure the second job as a successor to the first job.

Restart a Windows serivce

Paste the following code into a file ./config/live/service_restart.job.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
 <job>
   <script language="shell"><![CDATA[ 
     %windir%\system32\net.exe stop wuauserv
   ]]></script>
   <run_time>
     <period single_start = "03:00"/>
   </run_time>
   <commands on_exit_code="success">
     <start_job job="service_start"/>
   </commands>
 </job>
Write a comment…