Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Print Spooler 1

Status
Not open for further replies.

netsmartcode

Programmer
May 3, 2004
3
CA
I am writing a program that has to capture when the user clicks the print button in any application and interupt it before printing. This interupt will need to store some information entered by the user into a database and then print the document. How do I go about capturing when a user uses the print command in any application and is there also a way that I can exclude certain applications from this interupt by having a list of .exes or something that will bypass the interupt?

Any help would be greatly appreciated.
 
netsmartcode,

When you say you want to do this is in any application, does that include non-VFP ones? If so, that's a pretty tall order. Short of writing your own printer driver, my guess is that it can't be done.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Or rewrite some API functions to intercept messages.

About the best you could possibly hope for would be to look for print jobs already queued and have the user enter data on new ones at that time.

Here is a routine to use WMI to query the print queue:
Code:
CREATE CURSOR QueueDetail;
   (adProperty c(25),;
    adValue    c(120))
      
oManager = Getobject("winmgmts:")
oPrintQ = ;
  oManager.InstancesOf("Win32_PrintJob")

FOR EACH Qualifier IN oPrintQ
  FOR EACH Property IN Qualifier.Properties_
     op = Property
     IF op.IsArray
         DIMENSION av[1]
         av = Property.Value
         FOR zzz = 1 TO Alen(av)
            APPEND BLANK 
            REPLACE adProperty WITH Property.name  
            REPLACE adValue    WITH Transform(av[zzz])
         NEXT
      ELSE 
        APPEND BLANK 
        REPLACE adProperty WITH Property.name  
        REPLACE adValue    WITH Transform(Property.Value)
      ENDIF 
     IF Property.name = 'Caption'
        ?Property.Value
     ENDIF 
  NEXT
NEXT


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Yes I want to be able to capture applications outside of VFP using "Print". I need to record certain information that the user will specify to track the printing details like number of pages and possibly what application printed and so on.

Now how would I go about making this run all the time, waiting for applications to have their print buttons used? The key thing is to have it running all the time waiting for a print job to enter the queue. I figured I would be having to deal with the Windows API for the print monitoring I just don't know how to go about integrating the two together. Can someone please provide me with a project example of a simple dialog popping up asking a single question and storing it into a table after "Print" has been choosen from an external application? I realize this is asking a lot but think of the possibilities one could do with this combination is huge. Again any help is greatly appreciated.
 
Can anyone help me here please? I need this to work on Windows 98/NT/2000/XP. So I don't know if the WMI will work in Windows 98.
 
WMI may or may not be installed on '98. If not, you can download and install it from the Microsoft web site.

The code in the above example provides a bunch of info on the print job. Even some unique info in the timestamp for segregating print jobs. You could add the user name using GETENV() or ID().
So, you could query the spooler on a regular interval and add the records to a table. If no additional info is required, run it as a COM server in the background and have it query the spooler every 5, 10, 30 or whatever seconds.
If at the addition of a printjob the user needs to enter some data, run the app minimized and pop up an input box or form to add additional data to a table when a new job is found.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top