Hey guys,
I'm having an issue with a script I've been working on that watches a folder for new files and then sends an e-mail when it finds a new file. It works perfectly when run manually from the command prompt or when scheduled in windows task scheduler. However, there are about 30 people in the office who each have a folder that needs to be watched so they can be notified when a new file is added to the folder. Since I'd prefer not to have to schedule the script for each of the folders 30 times, I wrote what I thought would be a simple batch file to launch the script for each user that could then be scheduled in the task scheduler. The batch file, launches the folder watching script without a hitch, but once a new file is added to the folder being watched I get the following error from the windows script host:
Script: G:\faxes\Fax Notify\user1\folderWatcher
.vbs
Line: 18
Char: 5
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)
Here are the other relevant script files:
folderWatcher.vbs:
'This script watches a folder and then runs the faxNotify program when a new file is found
Set objShell = CreateObject("Wscript.Shel
l")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotifica
tionQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile
' and " _
& "TargetInstance.GroupCompo
nent= " _
& "'Win32_Directory.Name=""G
:\\\\faxes
\\\\eugene
m""'")
'modify the folder name to match the directory being watched
Do
Set objLatestEvent = colMonitoredEvents.NextEve
nt
objShell.Run("faxNotify.ba
t ")
Loop
runFolderWatcher.bat - Batch file that launches the folderWatcher program for each user:
start wscript "G:\faxes\Fax Notify\user1\folderWatcher
.vbs"
start wscript "G:\faxes\Fax Notify\user2\folderWatcher
.vbs"
start wscript "G:\faxes\Fax Notify\user3\folderWatcher
.vbs"
start wscript "G:\faxes\Fax Notify\user4\folderWatcher
.vbs"
The faxNotify.bat file is in the same folder as folderWatcher.vbs. When run manually from the command prompt or scheduled in the task scheduler it works perfectly. I've tried hard-coding the path of the faxNotify.bat file in the folderWatcher.vbs file and get the same error. Does anyone know what I'm doing wrong? Thanks.