12

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?

1 Answer 1

17

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'.

4
  • What is the Path here? how I can find out path of the service, that I want to work with? Commented Feb 5, 2018 at 15:54
  • 1
    @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
    Commented Feb 5, 2018 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? Commented Feb 6, 2018 at 5:14
  • Glad it worked out. This answer doesn't work because there is no such thing as "running". there are only few options like disabled, auto start (automatic in services), demand start (manual in services). there are other mistakes too like no param 3, and problems in the format. Commented Feb 6, 2019 at 19:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .