Solved

How To Monitor Printer Activities in Win98?

Posted on 2003-11-19
11
630 Views
Last Modified: 2012-05-04
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
Comment
Question by:limva
  • 5
  • 5
11 Comments
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
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
 
LVL 2

Expert Comment

by:Merrion
Comment Utility
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
 
LVL 2

Expert Comment

by:Merrion
Comment Utility
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
 

Author Comment

by:limva
Comment Utility
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
 

Author Comment

by:limva
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Merrion
Comment Utility
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
 

Author Comment

by:limva
Comment Utility
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
 

Author Comment

by:limva
Comment Utility
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
 
LVL 2

Accepted Solution

by:
Merrion earned 200 total points
Comment Utility
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
 

Author Comment

by:limva
Comment Utility
The answer is to go NT or Windows 2000.

Thanks Merrion!
0
 
LVL 2

Expert Comment

by:Merrion
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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