The VBS script works outside of SQL server but not when executed from within a SQL Server Stored Procedure using this code:
SET @VBSCommandLine ='cscript.exe C:\PrintLabels\TestVBS.vbs //H:CScript //Nologo'
EXEC master..xp_cmdshell @VBSCommandLine
The VBS code dies when it gets to the appRef.Open("C:\PrintLabels\PLT.ait") statement saying the the server has thrown an exception.
'PrintLabel.vbs 'Suppresses user input ' Open input doc 'Places the files Dim fileNames(2) dim imageLeft ' Place the first image Call AddRasterItemToPage(docRef, fileNames(1), imageLeft, imageTop, (imageSize) ) ' Place the second image Call AddRasterItemToPage(docRef, fileNames(2), imageLeft, imageTop, (imageSize) ) myOutputFile = "C:\PrintLabels\TempAIFile\TempLabelAutoTest.ai" Set jobOptionsRef = CreateObject("Illustrator.PrintJobOptions") docRef.Close() 'Exits Adobe Illustrator appRef.Quit Wscript.echo("just after exit") ' This routine adds all images in the folder as RasterItems Sub AddRasterItemToPage(aDocument, theFile, imageLeft, imageTop, imageSize) End SubThe VBS Script File
'This script opens an ai template, plays some actions to import two images, prints the file,
' and quits ai without saving the file
'
Wscript.echo("Before Illustrator")
Set appRef = CreateObject("Illustrator.Application.CS5.1")
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
appRef.UserInteractionLevel = -1
appRef.Open("C:\PrintLabels\PLT.ait")
Set docRef = appRef.ActiveDocument
inputFileName = docRef.Name
Wscript.echo("Before Place files")
set sDirName = "C:\PrintLabels\PSDFiles"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\PrintLabels\PSDFiles")
Set fls = fldr.Files
i = 1
num = 0
Dim aFile
For each aFile in fls
' Ignore system files.
If not aFile.attributes and 4 Then
num = num + 1
fileNames(num) = CStr(aFile)
End If
Next
dim imageTop
dim imageSize
imageLeft = 18
imageTop = -423
imageSize = 5.0
imageLeft = 18
imageTop = -31
imageSize = 5.0
docRef.SaveAS (myOutputFile)
Wscript.echo("After save file")
Set printOpts = CreateObject("Illustrator.printOptions")
jobOptionsRef.Designation = 0 'aiVisiblePrintableLayers
jobOptionsRef.Copies = 1
printOpts.JobOptions = jobOptionsRef
printOpts.PrinterName = "OCIO-CapGal-4071A-1"
printOpts.PrintPreset = "3/4 Sticker Print"
Wscript.echo("Before print")
docRef.PrintOut printOpts
Set docRef = Nothing
Wscript.echo("just before exit")
' to the Document
' Create a new raster item and link it to the image file
Set aPlacedItem = aDocument.PlacedItems.Add
aPlacedItem.File = theFile
' Move the raster item
aPlacedItem.Position = Array(imageLeft,imageTop)
Exit Sub