I removed the space in the folder so that it's now FaxNotify. I also tried removing the space after faxNotify.bat on the 18th line of folderWatcher.vbs. Unfortunately, neither helped. I'm still getting the same error.
Main Topics
Browse All TopicsHey 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
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
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotifica
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile
& "TargetInstance.GroupCompo
& "'Win32_Directory.Name=""G
'modify the folder name to match the directory being watched
Do
Set objLatestEvent = colMonitoredEvents.NextEve
objShell.Run("faxNotify.ba
Loop
runFolderWatcher.bat - Batch file that launches the folderWatcher program for each user:
start wscript "G:\faxes\Fax Notify\user1\folderWatcher
start wscript "G:\faxes\Fax Notify\user2\folderWatcher
start wscript "G:\faxes\Fax Notify\user3\folderWatcher
start wscript "G:\faxes\Fax Notify\user4\folderWatcher
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.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thank you both.
After trying what you suggested, jkr, I didn't get the usual error listed above. Instead, everything ran normally until I got the following message from the Windows Script Host: Can not find script file "G:\faxes\Fax Notify\eugene\folderWatche
No email was sent when a test file was added to the folder being watched. The strange thing about the error is that it shouldn't be able to find "G:\faxes\Fax Notify\eugene\folderWatche
Do
Set objLatestEvent = colMonitoredEvents.NextEve
objShell.Run("D:\Imagestor
Loop
So I don't understand why it was looking for 'Fax Notify' folder in the first place. The batch file that launches the script was also updated:
start wscript "G:\faxes\FaxNotify\eugene
Update:
At the moment, the files look like this:
folderWatcher.vbs:
'This script watches a folder and then fires off the faxNotify program when a new file is detected
Set objShell = CreateObject("Wscript.Shel
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotifica
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile
& "TargetInstance.GroupCompo
& "'Win32_Directory.Name=""G
'modify the folder name to match the directory being watched
Do
Set objLatestEvent = colMonitoredEvents.NextEve
objShell.Run("G:\faxes\Fax
Loop
runFolderWatcher.bat:
start wscript "G:\faxes\FaxNotify\eugene
When runFolderWatcher.bat is started from the cmd prompt, it starts running and an instance of wscript.exe shows up in the task manager. Once a file is added to the folder being watched, a window flashes on the screen for an instant. Normally, this is the bat file that sends the email, however, it doesn't remain on screen long enough for me to read anything and no email is sent. The way the files are now, everything works when started manually (i.e., without the runFolderWatcher.bat), and when a file is added to the folder being watched the appropriate notification email is sent. This leads me to believe that the issue is the runFolderWatcher.bat file, but I don't know what that issue might be. Any thoughts or ideas on this would be greatly appreciated. Thanks!
Thanks for that tip, Rob. It led me to the solution. The problem was that the batch file was running from the FaxNotify folder instead instead of the user's folder and the mailsend program that the batch file was looking for was in the user's folder. Moving the mailsend program to the FaxNotify folder fixed the issue. Thanks again!
Business Accounts
Answer for Membership
by: keith_alabasterPosted on 2009-08-10 at 10:46:59ID: 25062179
Wondering whether the script does not like the space in 'fax notify'.