• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Scheduled process to print and delete


Is there a way to monitor the contents of a folder (PDF files) on a scheduled task to print to a printer and delete (the file) after successful print? The line of business will dump PDF reports into a folder - I want a scheduled task to monitor this folder, print, and delete.


  • 4
  • 2
2 Solutions

This is straight forward enough to achieve using VBScript & Windows Scheduled Tasks.

This code will process files within a target folder, if the file is a PDF then it will, using the Wscript Shell object run the Acrobat Reader executable with some command line parameters.

It will print the documents to the default printer on the machine.
On Error Resume Next

' Set a String value to the path of the folder to be processed
FolderToMonitor = "C:\MyDev"

' Set the File System Object so we can access Folders and Files
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

' Get the Folder to be processed so we can use the item within it
Set Folder = FileSystemObject.GetFolder(FolderToMonitor)

' Get all the files currently in the folder
Set Files = Folder.Files
' Loop throuhg the list of files
For Each File In Files

	' Get the File Name
	FileName = File.Name
	' Check that the file is a PDF
	If Right(UCase(FileName), 3) = "PDF" Then
		' Clear any error codes
		' Set and use the Wscript Shell object to run a command
		Set WscriptShell = CreateObject ("Wscript.Shell")
		WscriptShell.run """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"" /p /h" & FileName,,True
		' If the Err Number returned is 0 (Success) then delete the file
		If Err.Number = 0 Then
			FileSystemObject.DeleteFile FileName
		End If
	End If

' Move on to the next file	

Open in new window

appliedimgAuthor Commented:
jawa29 - thanks much for your response.

I used your script but unfortunately it neither prints not deletes the files. I've added to display msgbox each step of the script and it hits all the loops and captures file name etc. The Err.Number value returned is also 0, however, nothing prints not deletes. Any thoughts?

Also, is it possible to specify the printer as well?
appliedimgAuthor Commented:
Also, I do get "There was an error opening this document. This file cannot be found." error message when I run the script and it launches Adobe Reader.Capture.JPG

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

appliedimgAuthor Commented:
I've used this script instead:

strComputer = "."
TargetFolder = "C:\Files\ToPrint\" 
Set objShell = CreateObject("Shell.Application") 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items 

For Each objItem In colItems 
	FileName = objItem.Name

	objItem.InvokeVerbEx ("Print") 


	objFSO.DeleteFile(TargetFolder & FileName), True


Open in new window

Hi there,

I'm glad you found a solution, I will look at why my script didn't work for my own curiosity.
appliedimgAuthor Commented:
My answer is what I was looking for. jawa29 did help with ideas for me to get there.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now