RE: Start scheduled batch file as soon as source file changes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Is There any process by which the file in destination drive will get updated
as soon as the file in the source drive is changed....

Prashant

"urkec" wrote:

You could use WMI InstanceModificationEvent. You can find about it in Windows
200 scripting guide.

I asked a similar question here, but it seems it is better to use Schedulde
tasks and copy needed files periodically.

Anyway, here is the script. The loop is infinite, so you would have to stop
the Wscript.exe and wmiprvse.exe processes manually.

Set fso = CreateObject ("Scripting.FileSystemObject")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " _
& "TargetInstance ISA 'CIM_DataFile' AND " _
& "TargetInstance.Name='c:\\scripts\\test.xls'")

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
fso.CopyFile "C:\scripts\test.xls", "D:\Archive\", true
Loop

--
urkec


"Prashant" wrote:

Hi all,

i have a mapped drive on Windows 2000 OS. I m copying the file from mapped
drive using a batch file which is scheduled.
Now what i want, the batch file should run as soon as the source file in
mapped drive is changed or updated (its a Excel file).

Solution & suggestion are appreciated.


.


Quantcast