Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-09
7
Medium Priority
?
896 Views
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
0
Comment
Question by:Craig_Campbell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 31

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.

Scott

BTW, I adapted this from several scripts I found at Hey Scripting Guy
   http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx
In particular, the page on files and folders
   http://www.microsoft.com/technet/scriptcenter/resources/qanda/files.mspx
had this sample
   http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb07/hey0214.mspx

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""'")
 
Do
    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)
 
    ' INSERT PRINT COMMAND HERE
 
    objfile.delete
 
    ' this is dumb but useful method for stopping script during testing
    if strfilename = "C:\temp\stop.jpg" then wscript.quit
Loop

Open in new window

0
 

Author Comment

by:Craig_Campbell
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.
script-conf.jpg
0
 
LVL 31

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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 31

Expert Comment

by:Scott Helmers
ID: 24120630
Craig,

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
   "C:\windows\system32"
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
Next
wscript.echo strVerbList

Open in new window

0
 

Author Comment

by:Craig_Campbell
ID: 24121764
Thanks Scott,

Here is the screenshot you requested.

Cheers,

Craig
Screenshot2.JPG
0
 
LVL 31

Accepted Solution

by:
Scott Helmers earned 2000 total points
ID: 24124176
Craig,

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.

Scott

Monitor-for-jpg-print-delete-v6.txt
0
 

Author Comment

by:Craig_Campbell
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,

Craig
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Make the most of your online learning experience.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Introduction to Processes
Suggested Courses

636 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