5

I want to run a scheduled task every time after a given service is started. I have looked for a way to set a trigger on a service start, so that the service in question may be started automatically at system start or manual restarted on run time.

The System it should work on is a Windows Server 2008 R2.

Detailed description:

  • On server A an UMS service is running
  • On server B a FAX line service is running and connects to the UMS service on server A
  • If server A or the UMS service on it is restarted the FAX service on server b is loosing its connection and has to be restarted.

So, I want to schedule a script on server A with the start of the UMS service and restart the FAX Line service on server B via net stop/start from that.

The missing point is, how would I define the trigger for the task scheduler?

14

You can do this using Task Scheduler with a Trigger set up as follows:

Begin the task: On an event

Settings: Custom

Click the New Event Filter... button

Select the XML tab

Check the Edit query manually checkbox

Click the Yes button

Enter the following in the text box, replacing your service name:

<QueryList> 
   <Query Id="0"> 
      <Select Path="System"> 
         *[EventData[Data[@Name='param1'] and (Data='YOUR SERVICE NAME')]] 
         and
         *[EventData[Data[@Name='param2'] and (Data='running')]] 
       </Select> 
   </Query> 
</QueryList>

More information on XML Event filtering here: Advanced XML filtering in the Windows Event Viewer.

Note: When using a non English Windows 'Data' for 'param2' depends on the system's language. E.g. for a German version of Windows it is 'Ausgeführt' instead of 'running'.

  • What is the Path here? how I can find out path of the service, that I want to work with? – Mehdi Dehghani Feb 5 '18 at 15:54
  • @MehdiDehghani you don't need to change the Path property - that is simply referring to the System Event Log. The only thing you need to change is YOUR SERVICE NAME – Shevek Feb 5 '18 at 22:02
  • I want to run task when Windows Update service started, I use wuauserv and Windows Update, but doesn't work, can you help me on this? – Mehdi Dehghani Feb 6 '18 at 5:14
  • 1
    @Mehdi Dehghani Follow this tutorial. nucuta.com/how-to-disable-automatic-updates-on-windows-10/… – Don Dilanga Feb 6 at 12:02
  • @DonDilanga works!, many thanks for the link. – Mehdi Dehghani Feb 6 at 13:14

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.