WatchDirectory Forum
watchDirectory forums >> Bug Reports >> Run VBS Script does not work

Message started by cbart on May 24th, 2011 at 7:59pm

Title: Run VBS Script does not work
Post by cbart on May 24th, 2011 at 7:59pm
The run vbs script task does not appear to fire the vbs script when a file is detected.
Recent messages shows that a file was detected in the monitored folder (i.e. FN - C:\claims\allrpts.pdf) but nothing happens.
I have two test scripts that I have tried, one is the vbs sample script which is not writing to history, the second is a test script that works fine from the command line but does not copy the file with watchdirectory.  I've listed both below.  

' This is a skeleton VBS file you can use with watchDirectory
' first, get all watchDirectory variables
' for an overview of their meaning, see the online help
' Plugins -> Automatically Run a .bat file -> Environment variables
' or, on the internet:
' The naming of the variables is almost the same as explained inside the above helpfile,
' but with all underscores removed, and properly Capitalized.
' So, WD_REASON becomes WdReason and WD_FILE_N becomes WdFileN

Dim WdReason, WdDir, WdFile, WdOfile, WdFileD, WdOfileD, WdFileN, WdOfileN
Dim WdFileB, WdOfileB, WdFileE, WdOfileE, WdReldir, WdOreldir, WdFileSize, WdFileSizeKb
Dim WdFileShortPath, WdFileShortName, WdInstDir, WdAnnotate, WdTaskDir, WdConfig
Dim WdCurrun, WdCurevt, WdDate, WdTime, WdDttm

Call GetEnvironmentVariables
Call writeToHistory("info", "Called for event " & WdReason & " file=" & WdFile)

'========================= Add your own code here ===============================

Call writeToHistory("info", "Done")

Function GetEnvironmentVariables()
     Dim oShell
     Set oShell = CreateObject("Wscript.Shell")
     WdReason = oShell.ExpandEnvironmentStrings("%WD_REASON%")
     WdDir = oShell.ExpandEnvironmentStrings("%WD_DIR%")
     WdFile = oShell.ExpandEnvironmentStrings("%WD_FILE%")
     WdOfile = oShell.ExpandEnvironmentStrings("%WD_OFILE%")
     WdfileD = oShell.ExpandEnvironmentStrings("%WD_FILE_D%")
     WdOfileD = oShell.ExpandEnvironmentStrings("%WD_OFILE_D%")
     WdfileN = oShell.ExpandEnvironmentStrings("%WD_FILE_N%")
     WdOfileN = oShell.ExpandEnvironmentStrings("%WD_OFILE_N%")
     WdfileB = oShell.ExpandEnvironmentStrings("%WD_FILE_B%")
     WdOfileB = oShell.ExpandEnvironmentStrings("%WD_OFILE_B%")
     WdfileE = oShell.ExpandEnvironmentStrings("%WD_FILE_E%")
     WdOfileE = oShell.ExpandEnvironmentStrings("%WD_OFILE_E%")
     WdReldir = oShell.ExpandEnvironmentStrings("%WD_RELDIR%")
     WdOreldir = oShell.ExpandEnvironmentStrings("%WD_ORELDIR%")
     WdFileSize = oShell.ExpandEnvironmentStrings("%WD_FILE_SIZE%")
     WdFileSizeKb = oShell.ExpandEnvironmentStrings("%WD_FILE_SIZE_KB%")
     WdFileShortPath = oShell.ExpandEnvironmentStrings("%WD_FILE_SHORTPATH%")
     WdFileShortName = oShell.ExpandEnvironmentStrings("%WD_FILE_SHORTNAME%")
     WdInstDir = oShell.ExpandEnvironmentStrings("%WD_INSTDIR%")
     WdAnnotate = oShell.ExpandEnvironmentStrings("%ANNOTATE%")
     WdTaskDir = oShell.ExpandEnvironmentStrings("%WD_TASKDIR%")
     WdConfig = oShell.ExpandEnvironmentStrings("%WD_CONFIG%")
     WdCurrun = oShell.ExpandEnvironmentStrings("%WD_CURRUN%")
     WdCurevt = oShell.ExpandEnvironmentStrings("%WD_CUREVT%")
     WdDate = oShell.ExpandEnvironmentStrings("%WD_DATE%")
     WdTime = oShell.ExpandEnvironmentStrings("%WD_TIME%")
     WdDttm = oShell.ExpandEnvironmentStrings("%WD_DTTM%")
     Set oShell = Nothing
End Function

' Write a message to the history database.
' params:
'   DIWEF   - The message type: debug, info, warn, error or fatal
'             Note that error and fatal messages will cause the task to abort!
'   message - The message to write to the history database.

Function writeToHistory(ByVal DIWEF, ByVal message)
     Set WshShell = WScript.CreateObject("WScript.Shell")
     Dim cc
     cc = WdAnnotate & " " & DIWEF & " " & message
     Call WshShell.Run(cc, 0, true)
     Set WshShell = Nothing
End Function

Dim sOriginFolder, sDestinationFolder, sFile, sDestinationFile, oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
sOriginFolder = "c:\claims" & "\"
sDestinationFolder = "I:\clmsirimport"
sDestinationFile = "CLMS_" & "tstfile" & "_10100_CORR________________C_001.pdf"
sFile = "clu.pdf"
oFSO.GetFile(sOriginFolder & sFile).Copy sDestinationFolder & "\" & sDestinationFile,True

Title: Re: Run VBS Script does not work
Post by Gert on May 25th, 2011 at 7:46am

The annotate functionality will only work if you enable the option to "capture output" for the task.

Your test script seems to use a drive "I:\"... Sounds like a mapped network drive to me. Please read this blogpost:


WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.