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?

fixer1234
  • 27,064
  • 61
  • 75
  • 116
Thomas
  • 123
  • 1
  • 1
  • 4

1 Answers1

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

Jawa
  • 3,619
  • 13
  • 31
  • 36
Shevek
  • 16,502
  • 7
  • 46
  • 75
  • What is the `Path` here? how I can find out path of the service, _that I want to work with_? – Mehdi Dehghani Feb 05 '18 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 Feb 05 '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 06 '18 at 05: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. – Don Dilanga Feb 06 '19 at 19:05