Using a VB Script with the AfterPrintProgram setting
This small example will show you how to run a VB Script from the
PDF printer after the document is created.
The principles used here are the same if you want to use it with the
RunOnSuccess or RunOnError settings.
The VB Script
For this example, I have created a small VB Script that takes a number
of parameters. These parameters are always passed to the programs
specified under AfterPrintProgram, RunOnSuccess, and RunOnError.
Option Explicit
Dim msg, args
Set args = Wscript.Arguments
msg = "Hello World!" & vbCrlf & vbCrlf
msg = msg & "Document path: " & args(0) & vbCrlf
msg = msg & "Pages: " & args(1) & vbCrlf
msg = msg & "File count: " & args(2) & vbCrlf
msg = msg & "Status file: " & args(3) & vbCrlf
MsgBox msg
Use the VB Script
In order to make the printer run the script, we have to specify it
in the AfterPrintProgram settings. This can be done in any of the
configuration files or by using the Options Dialog found in the
Windows start menu.
Note that the full path of the VB Script is surrounded by quotes to make
sure it works if the path contains spaces. You should also note the ! in
front of the command. This will make the printer execute the command in
Shell Execute mode, which is the same as if you run it using the run box
found in your Windows start menu.
If you leave out the ! then the printer will think the VB Script is
an executable file type and fail.
If you do not want to run the script in Shell Execute mode or want to
run the script in 32-bit mode on a 64-bit system then you can change the
command to something like this.
c:\windows\syswow64\wscript.exe "C:\test\example.vbs" "%1" "%2" "%3" "%4"
Hopefully this will give you a head start on working with these
features of the program.
|