[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

How To Monitor Printer Activities in Win98?

I am using VB6 and Win98.

I need to write a program running in the background that would allow only 5 pages to be printed, whether from MS Word, Excel, Webbrowser, etc.  After the 5th page printed, no printing would be allowed.

There is only 1 printer connected to the computer and no network connections.

Please help!  I can increase the points if this turns out to be a tough one.

0
limva
Asked:
limva
  • 5
  • 5
1 Solution
 
DhaestCommented:
See http://www.merrioncomputing.com/Programming/WatchPrinter.htm It can be helpful for you
--> complete source code included
maybe this can help:
-->http://www.karenware.com/powertools/ptprnlog.asp

0
 
MerrionCommented:
The former link is only for Windows NT, 2000 and XP systems - for Windows 9x you need to subclass your application main window and look out for the WM_SPOOLERSTATUS window message.  Note that printer monitoring from Windows 9x is a lot less accurate and reliable than is the case in NT and derived systems.
0
 
MerrionCommented:
The former link is only for Windows NT, 2000 and XP systems - for Windows 9x you need to subclass your application main window and look out for the WM_SPOOLERSTATUS window message.  Note that printer monitoring from Windows 9x is a lot less accurate and reliable than is the case in NT and derived systems.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
limvaAuthor Commented:
Thanks Merrion.  Sorry I couldn't get back to you earlier because the internet wasn't working for me this morning.  I'll take a look at your suggestions and let you know tomorrow.

0
 
limvaAuthor Commented:
Hi Merrion.

This might be too much to ask.  Would you be able to give me the API codes or at least point me to examples for doing the following:?

1. Set a hook to raise an event when there is an attempt to print.
2. Determine the number of pages user is attempting to print.
3. Programmatically cancel the printing job if program determines the print pages have exceeded the limit.

There is just 1 printer and 1 computer, both local.

If the solution deserves more points please let me know.

Thanks!
0
 
MerrionCommented:
I can't reliably do #1 as I don't have access to a Win98 machine to test it - however it is the general "subclassing a window in VB" example looking for WM_SPOOLERSTATUS

Public Const WM_SPOOLERSTATUS = &H2A


For 2 use the EnumJobs and GetJob APIs as per this article:
http://www.merrioncomputing.com/Programming/PrintJob.htm

For 3 use the SetJob API call with the command as per this code:
http://www.merrioncomputing.com/EventVB/EventVB~ApiPrintJob_CODE.html
'---
lret = SetJob(mhPrinter, mJobId, 0, 0, JOB_CONTROL_CANCEL)

0
 
limvaAuthor Commented:
Hi Merrion.  I haven't forgotten this question.  I will try to follow your suggestions above as best as I can over the weekend and let you know.

Thanks!
0
 
limvaAuthor Commented:
Hello Merrion.  Sorry for the gap in time.  I was working on another project.

Apparently Windows 98 does not report print spool info accurately.  I tried opening the spool file (*.SPL) in the C:\Windows\spool\Printers\ folder and parse it to count the pages to be printed and was successful, but it turned out that the SPL file format is different for each printer, depending on its driver.  So I cannot use that.

What I have concluded is just to change the OS from Win98 to either Win NT or Win2000.  My question is, Merrion, can I use my current version of VB6 on Win NT or Win2000?  Or is there a different version of VB6 for NT?


Thanks!
0
 
MerrionCommented:
The spooler subsystem is entirely different between (a)windows 95/98/Me and (b)NT4/XP/2000

In case (a) whenever a print job is spooled a WM_SPOOLERSTATUS message is broadcast to top level windows and they can intercept it.  Also a seperate ~.tmp file is created for every page of a print job.  This is always in the printer specific raw format

In case (b) the printer can be monitored by setting a FindFirstPrinterChangeNotification handle and every print job has a .spl file and a .shd file.  You can opt to store the spool files in RAW format or as EMF formatted file, in which case the .spl file is a collection of EMF records, one for each page.

Printer logging is notoriously unreliable in case a which is why most commercial offerings are for (b) only.
0
 
limvaAuthor Commented:
The answer is to go NT or Windows 2000.

Thanks Merrion!
0
 
MerrionCommented:
Note that only the print server need be NT/2000/XP for all that stuff to apply....and (IMHO) it should be anyway from a security point of view.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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