6

Is there a way to run a specific script each time Windows update completes (i.e., after reboot or after an update that doesn't require a reboot)?

My application is suffering from MSCOMCTL.OCX updates, and it seems that every time Windows Update updates, the user is required to apply my fixup script.

EDIT: For Windows 7 and later.

krlmlr
  • 493
  • 1
  • 5
  • 17

1 Answers1

13

I believe, ultimately, the correct answer is "Fix your application". However, you may not be able to for any number of reasons. That being said...


Which version of Windows? In Vista/2008 and up, you can tie Scheduled Tasks to specific Event IDs. In the System event log, Event ID 19 from WindowsUpdateClient, indicates successful WUA Update Installation.

Event Viewer WindowsUpdateClient Event ID 19

Launch the Task Scheduler snap-in, taskschd.msc. Right click the "Task Scheduler Library" and select "Create Basic Task...".

Create Basic Task

In the next screen, input a name and a brief description and click "Next".

Generic name and description

Click the radio button labeled "When a specific event is logged", click "Next".

When a specific event is logged

Select "System" as the log, "WindowsUpdateClient" as the source and "19" as Event ID, click "Next".

Log source and event ID

Click the "Start a program" radio button, click "Next".

Start a program

Provide the path to your "fix it" script or executable, click "Next".

path to script

Review your settings are correct, then click "Finish".

enter image description here

You will now see the Scheduled Task listed in the library with your settings.


Here is a command line example using only C:\Windows\system32\schtasks.exe, the XPath filter syntax took me a while. It appears the Task Scheduler uses only a subset of XPath.

REM Create scheduled task triggered by WindowsUpdateClient event ID 19
schtasks /Create /TN "Post WUA Update Install" /TR "C:\scripts\your.fix.cmd" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-WindowsUpdateClient'] and (EventID=19)]]"
jscott
  • 24,204
  • 8
  • 77
  • 99
  • 1
    This is amazing, thank you! Will I be able to use [task scheduler scripting](http://msdn.microsoft.com/en-us/library/windows/desktop/aa383607(v=vs.85).aspx) to automate the setup? – krlmlr Aug 25 '13 at 21:27
  • 2
    I'm out and about right now, but yeah, [`schtasks.exe`](http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx) supports `ONEVENT` so you should be able to... I may knock together a Powershell example if I get the time. Note that Group Policy Preference Client Side Extensions also allow for creating Scheduled Tasks. – jscott Aug 25 '13 at 21:44
  • 1
    @krlmlr I've added a simple command line example which you should be able to utilize in your automations. – jscott Aug 26 '13 at 13:08