Tip

How to receive automatic notification of file changes

The prolific (and very funny) Microsoft Scripting Guy site offers a simple piece of VBScript

Requires Free Membership to View

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.

This was first published in November 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.