A few weeks ago the there was a need to monitor some DNS Server events and trigger some tasks in one of my customer environments which is build on top of Windows Server 2003.
As you already know Windows Server 2008 and later has already this UI in Scheduled Tasks to monitor and trigger tasks under specific conditions. It’s very easy to configure it over the graphical user interface.
In Windows Server 2003 under scheduled tasks there isn’t such options. Under Windows Server 2003 we have to use the good, old command line tool, eventtriggers.exe to monitor and trigger a task.
More information about the syntax of eventtriggers can be found under:
http://technet.microsoft.com/en-us/library/bb490901.aspx
I have created the following scheduled task with eventtriggers.exe. In the below example Eventtriggers will monitor for Event ID 111 under “DNS Server” events and will trigger C:\DNSRestart.bat if the event occurs. It will use the System Account which is defined with the /ru parameter.
Example :
eventtriggers /create /tr “DNS Restart” /l “DNS Server” /eid 111 /t error /tk C:\DnsRestart.bat /ru “System”
The batch file looks like below. It will first stop the dns service and wait 90 seconds. A wait variable is not available in cmd.exe therefore we are pinging the host itself 90 seconds long and after that the service will be started again.
Save the Batch file under : C:\DNSRestart.bat .
net stop dns
@ping 127.0.0.1 -n 90 -w 1000> nul
net start dns