Poll a network folder for new files/ images and automatically print them to a specific printer

Posted on 2009-04-09
Last Modified: 2013-11-10
Hi all,

I need a script or (preferably free) program that will meet the following requirements:

1) Poll a network folder for new JPEG image files (for example, every 5 minutes)
2) If there is a new file, print it to a network printer
3) Once printed, delete the file

Does anyone know of anything, or direct me to something that will do this?
It will be run in a Windows environment
Question by:Craig_Campbell
  • 4
  • 3
LVL 30

Expert Comment

by:Scott Helmers
ID: 24107239
I think I've got everything here you need -- except for the printing. Refer to comments in the script for information about how it works and where you'll need to insert the print command. I'll try to get back to this later to figure out the printing part (I need to do some real work now!) but if someone else can contribute that part, that would be great.

Note that you can change the time interval for how often the script checks for new files.


BTW, I adapted this from several scripts I found at Hey Scripting Guy
In particular, the page on files and folders
had this sample

wscript.echo "starting now"

Set objShell = CreateObject("Wscript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

' statement below creates event that monitors a folder (C:\test) for new files every 60 seconds


' change number here: "WITHIN 60" to change timer from 60 seconds to another value


' specifying directory name is weird: you must type four backslashes for each backslash

' you need in path;

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _

    ("SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE " _

        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _

            & "TargetInstance.GroupComponent= " _

                & "'Win32_Directory.Name=""c:\\\\test""'")


    Set objLatestEvent = colMonitoredEvents.NextEvent

    strNewFile = objLatestEvent.TargetInstance.PartComponent


    arrNewFile = Split(strNewFile, "=")

    strFileName = arrNewFile(1)

    strFileName = Replace(strFileName, "\\", "\")

    strFileName = Replace(strFileName, Chr(34), "")

    ' comment this out when everything is working

    wscript.echo "filename: " & strfilename

    set objFile = objFSO.GetFile(strFilename)



    ' this is dumb but useful method for stopping script during testing

    if strfilename = "C:\temp\stop.jpg" then wscript.quit


Open in new window


Author Comment

ID: 24112858
Thanks Scott,

That is looking great so far. Thanks for your time and effort, it is greatly appreciated.

One question, whenever I run the script a popup box comes up with the filename of the new file added to the folder (I have attached a jpeg of the popup). Is there a way to make this silent and automatically select OK on the confirmation box or something?

Also, if you could help with the print function that would be great.

Thanks again for your help mate.
LVL 30

Expert Comment

by:Scott Helmers
ID: 24112933
I just put that dialog in for testing purposes; look for this line
   wscript.echo "filename: " & strfilename
and either delete it or put an apostrophe (single quote) in front of it to comment it out.

You timing is good -- I just sat down to see whether I can solve the printing problem. No promises for tonight but I'll see what I can find.
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

LVL 30

Expert Comment

by:Scott Helmers
ID: 24120630

I may have stumbled onto the right path...

The script below will list all of the verbs we can apply to a jpg file; one of them should allow us to print it (it says here in fine print).

In the script, change
to the path containing the folder you want to monitor.

Put a jpg file into that folder then change "notepad.exe" to the name of the file.

Run the script and post a screen shot of the results here.

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace("C:\windows\system32")

Set objFolderItem = objFolder.ParseName("notepad.exe")


Set colVerbs = objFolderItem.Verbs

For Each objVerb in colVerbs

    strVerbList = strVerbList & objVerb & vbCRLF


wscript.echo strVerbList

Open in new window


Author Comment

ID: 24121764
Thanks Scott,

Here is the screenshot you requested.


LVL 30

Accepted Solution

Scott Helmers earned 500 total points
ID: 24124176

Progress! Armed with the print command from your dialog and what I found yesterday, the script is closer to the end objective. I think there are two deficiencies at the moment but both can be overcome.

On my system, the jpg print command launches the Windows picture manager, which requires user intervention to complete the printing. I assume one of two things is true on your system: either a different program is associated with printing jpgs and it runs unattended, or you print in a different way. For example, if you print from the command line, let me know the exact syntax that you use and we should be able to replicate it in the script.

The second deficiency is related to timing and is actually a secondary effect of the first problem described above -- because manual intervention takes time, i had to insert an artificial sleep timer (currently set for 20 seconds). This allows me to complete the printing before the script tries to delete the file. Without this delay, the file is gone before I can print it!

The easiest way to solve both problems is probably to print from the command line. I can do that in a way that pauses the script until the printing event completes, which, I think, will do the trick.

One other note: you can now set the name of the folder you want to monitor and the time intercal for monitoring. Just look for the comments that say SET FOLDER NAME HERE and SET MONITOR INTERVAL HERE.

I just realized I lied above -- there is a third deficiency: the script prints to the default printer. It will take some more work to get it to print to a network printer. You might consider asking that as a related question because it will take some investigation, or perhaps one of the other experts will know that answer.



Author Comment

ID: 24144045
Sorry Scott,

Only just got back online mate.Yeah, everything works great except for the Printing Wizard requiring user intervention. I have tried a few different programs and the command line (net use, net rint etc) but with no success so far. I wonder if there is a silent switch at the command line for any third party programs? Will have to investigate this and get back to you.

Cheers mate,


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now