The prolific (and very funny) Microsoft Scripting Guy site offers a simple piece of VBScript that monitors a given file for changes, and then automatically fires off a notification in a text window if something has (or hasn't) changed.
The script in question monitors a file that is ostensibly an application's log file, which is one of the many possible applications for this script. It also runs in a continuous loop, so it doesn't need to be run more than once to work its magic.
For the best results, run this script from the console and not from the GUI. Otherwise, it's difficult to terminate easily without breaking out Task Manager.
There are several ways to modify this script, such as polling a remote computer rather than a local one for any changes. Obviously this only works if the remote computer can be accessed over the network via NetBIOS (check those firewalls and policies).
The Scripting Guy site has how-to instructions that are not difficult to implement. The hardest part is making sure the remote computer processes the commands correctly.
Another script modification is to change the sleep state for the script -- i.e., to make it wait for a different period of time. To do this, you take the number of seconds you want to wait, multiply it by 1,000, and then change the Wscript.Sleep statement in the script to use the calculated number.
To wait an entire hour, use the value 1800000; to wait a mere minute, use 60000. On most modern hardware you could even poll every 10 seconds (10000) without incurring a significant amount of overhead.
Finally, you can also modify the script so that it only does something when changes are detected. To do that, just place the commands in question to run in the first part of the if block at the end of the script:
If strLatestTimestamp <> strOriginalTimestamp Then strOriginalTimestamp = strLatestTimeStamp [other commands go here] Else [rest of script]
One possible addition is sending an email using the blat command-line mailer:
Set g_shell = CreateObject("WScript.Shell") g_shell.Run(blatCommand, 0, True)
In the code above, blatCommand is the command-line string that executes blat and sends whatever message is needed.
ABOUT THE AUTHOR
Serdar Yegulalp is editor of Windows Insight (formerly the Windows Power Users Newsletter), a blog site devoted to hints, tips, tricks and news for users and administrators of Windows NT, Windows 2000, Windows XP, Windows Server 2003 and Vista. He has more than 12 years of experience working with Windows and contributes regularly to SearchWinComputing.com and other TechTarget sites.