How to monitor a file in windows for changes and run a program when it changes
How in Windows do I make a batch file that watches for the file to change then execute command?
for example, the file is c:\temp\lastbarcode.txt
strComputer = "."
Set objShell = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE " _
& "TargetInstance ISA 'CIM_DataFile' and " _
& "TargetInstance.Name='c:\\temp\\lastbarcode.txt'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
' HERE IS Where You would specify the command you wish to execute
' something along the lines of : objShell.Run [Enter Your Application Name Here]
comd="c:\windows\system32\notepad.exe c:\temp\lastbarcode.txt"
objShell.Run comd
WScript.Echo "Now - " & Now()
Loop
Looking for relevant Microsoft Windows Whitepapers? Visit the SearchWinIT.com Research Library.