DirMon SwiftView Tools Directory Monitor External Spec Glenn Widener Release 2.8 11/30/08 DirMon is simple utility that monitors directories for files, and runs a specified program on each file that appears. It is designed and supported only for use with Application Server-licensed SwiftPublish, SwiftConvert, or SwiftStamp, but could have many other uses. Typically, it is used to deploy a service such as file conversion on a network file server. The converter is licensed to execute on one server, and input and output directories on that server are made accessable via file service from all client systems. Licensing At this time, there is no physical licensing control of DirMon. Our license terms do not allow it's use except with an application server- or network-licensed SwiftView Tools product. Contact sales@swiftview.com if you are interested in other uses of the tool. Deployment DirMon is included in the 2.7 release of SwiftPublish, and is automatically started when SwiftPublish is installed. DirMon can be deployed separately from SwiftPublish as follows: - copy SwiftPublish v2.7 spcommon.dll and spauthserv.exe to c:\windows\system32 - configure registry settings as described below, using the dirmon.reg file included in the SwiftPublish installer - execute c:\windows\system32\spauthserv -i You can start and stop the service from the Start...Control Panel...Administrative Tools...Services user interface. Note that SwiftPublish will not function properly if the "SwiftView Tools" Service is stopped, or executed under a non-Adminstrative login, as the service is also used to perform various functions internal to SwiftPublish. Operation DirMon can monitor any number of directories. Every 3 seconds it examines each directory for files that have been written and closed. Each closed file is moved to another directory and a configured program is run. The file can be optionally deleted or moved to a save directory when the program finishes, in which case DirMon waits until completion to process more files, allowing simple system load management. If these options are not used, typically the program must delete the file itself on completion (see the SwiftConvert "set onexit" and "unlink" ICS commands). For all directories that have the delete or savedir option selected, DirMon will start up to a configured maximum number of simultaneous programs. By default, this maximum is the number of processors in the CPU. Without the delete option, DirMon starts the program in the background and moves on immediately to the next file, or goes to sleep if there are no files left to process. Thus, multiple operations will be running simultaneously. Note that currently the program must be a strictly batch utility, and may not interact with a user, as it is running under an NT service (not as the user who created the file). Because of this, it is important that any printing application for a file converted by spbatch under dirmon not display any dialogs to the user during printing. Some applications may need to be run manually once to click through initialization dialogs to prevent this. Configuration Currently, DirMon is configured by direct editing of the registry. All configuration is in windows registry string REG_SZ values, under: HKEY_LOCAL_MACHINE\Software\SwiftView\dirmonN, where N = 1, 2, ... All directories should be full paths, and will be created automatically if they do not already exist, indir and outdir with open read/write permissions to all users: indir directory in which files will be deposited Caution: do not set this to a directory containing permanent files, as they will all get processed and deleted! outdir directory in which result files are to be placed If unspecified, same as indir. workdir directory to which files are moved to begin processing May not be the same as indir. If unspecified, same as outdir. If a command fails, the file will be left in workdir. savedir directory to which files are moved when processing is complete. Causes waiting for completion, same as remove option. command A command line template string for the process to run. The line must begin with a full path to the program to run, including any suffix, quoted if the path contains spaces. If the program does not exist, the dirmon entry is silently ignored (v 2.7.1+). The command may contain "percent escapes" that are replaced as follows to generate the actual command to be run on each file: %in The full path and name of the input file in the workdir %outdir The outdir setting %inbase The simple (no dirs) name of the input file, with any dot-suffix stripped off remove y or Y if DirMon is to wait for program completion and delete the input file before starting another task. If the program does not complete within 15 minutes, operation proceeds anyway (with an error reported to the Windows application event log.) Default is to proceed immediately with the next task, leaving input file deletion to the command program. For now, at most one occurance of each substitution is supported. The program is started iconified in case it has a GUI, DOS windows suppressed in case it is a DOS program. It's stdout and stderr are redirected to the SwiftPublish logfile as configured by HKEY_LOCAL_MACHINE\Software\SwiftView\SwiftPublish\LogPath, default C:\Program Files\SwiftView\temp\swiftpublish.log. Any errors encountered by DirMon are also logged here. Note that environment variables expressed as $VARNAME are currently not replaced with the current environment variable setting in DirMon's environment. By default, as many operations with remove=y or savedir defined may execute simultaneously as the number of processors in the system. This default can be overridden with the following DWORD setting: HKEY_LOCAL_MACHINE\Software\SwiftView\dirmon\MaxProcs This registry entry is automatically set to the number of processors, at install, or if it is set to zero or greater than it's maximum value of 50. The following sample configurations are created when you install SwiftPublish: Convert PCL/HPGL/TIFF to PDF with SwiftConvert: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon1] label=Convert To Pdf indir=c:\program files\swiftview\converttopdf outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\converttopdfwork command="c:\program files\swiftview\sview.exe" -v1 -c"set service on|ldoc ""%in""|save PDF all ""%outdir\%inbase.pdf"" onefile" remove=y Convert PCL/HPGL/TIFF to TIFF with SwiftConvert: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon2] label=Convert To Tiff indir=c:\program files\swiftview\converttotiff outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\converttotiffwork command="c:\program files\swiftview\sview.exe" -v1 -c"set service on|ldoc ""%in""|save TF_G4 all ""%outdir\%inbase.tif"" onefile" remove=y Convert anything to PCL with SwiftPublish: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon3] label=Import To Pcl indir=c:\program files\swiftview\importtopcl outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\importtopclwork command="c:\program files\swiftview\spbatch.exe" -t -1 -s PostProcess="" OutputProgram="" Zip=n FilenameEnabled=y Filename="%outdir\%inbase.pcl" "%in" remove=y Convert anything to PDF with SwiftPublish: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon4] label=Import To PDF indir=c:\program files\swiftview\importtopdf outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\importtopdfwork command="c:\program files\swiftview\spbatch.exe" -t -1 -s PostProcess="c:\Program Files\swiftview\sview -l%l -v1 -c'set service on|set quotechar ^|ldoc ^%i^|set printres original|save PDF all ^%o^ onefile'" OutputProgram="" Zip=n FilenameEnabled=y Filename="%outdir\%inbase.pdf" "%in" remove=y Convert anything to TIFF with SwiftPublish: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon5] label=Import To Tiff indir=c:\program files\swiftview\importtotiff outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\importtotiffwork command="c:\program files\swiftview\spbatch.exe" -t -1 -s PostProcess="c:\Program Files\swiftview\sview -l%l -v1 -c'set service on|set quotechar ^|ldoc ^%i^|set printres original|save TF_G4 all ^%o^ onefile'" OutputProgram="" Zip=n FilenameEnabled=y Filename="%outdir\%inbase.tif" "%in" remove=y Test your SwiftConvert licensing: [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon6] label=Test SwiftConvert License indir=c:\program files\swiftview\testlicense outdir=c:\program files\swiftview\convertout workdir=c:\program files\swiftview\testlicensework command="c:\program files\swiftview\sview.exe" -v1 -c"set service on|gui dialog copyright" remove=y Print a PDF file to the SwiftPublish printer (configurable to any printer): [HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\dirmon7] label=Print a PDF file indir=c:\program files\swiftview\printpdf workdir=c:\program files\swiftview\printpdfwork command="c:\program files\swiftview\pdf\printpdf.exe" "%in" "SwiftPublish" remove=y These configuration are created using a sample .reg file which is installed in c:\Program Files\SwiftView\dirmon.reg for your convenience in redefining and reinstalling the configuration. SwiftPublish 2.8 includes a GUI configuration utility for DirMon. Notes: The ICS "set onexit" command is new in v8.2. spbatch now recognizes single quotes in it's parameter=value arguments, and converts them to double quotes, e.g. for the PostProcess command shown above. Debugging and Error Logging SwiftPublish and DirMon log errors to the Windows System Event Log, visible from Control Panel...Administrative Tools...Event Viewer...Application. SwiftView and SwiftConvert 8.1 also log errors here, so they can be debugged when run under DirMon. You can optionally enable display of error messages to the console; this feature should be disabled for production systems with this registry setting: HKEY_LOCAL_MACHINE\SOFTWARE\SwiftView\SwiftPublish\ServiceErrorDialogs: DWORD 0 (You can configure this setting from the DirMon configuration GUI.) SwiftView/SwiftConvert 8.5 adds an ICS command "set service on" that adjusts all message boxes for execution under a service, and forces -v1. Until this is released, DirMon needs to run under the Local System account, with "Allow service to interact with the desktop" checked, and sview run with the -v1 option, for SwiftView/SwiftConvert messages to be displayed. (The SwiftPublish installer enables Local System desktop access automatically). Other printing application message boxes typically cannot be seen either unless DirMon is configured this way under the Local System account. Note that sometimes events are slow to appear in the Event Viewer. Click F5/refresh, or restart the viewer to be sure you are seeing all events.