Solved

How To Monitor Printer Activities in Win98?

Posted on 2003-11-19
11
633 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
ID: 9785196
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
ID: 9785714
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
ID: 9785715
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
ID: 9795311
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
ID: 9799270
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
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.

 
LVL 2

Expert Comment

by:Merrion
ID: 9809146
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
ID: 9840272
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
ID: 9938138
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
ID: 9938339
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
ID: 9943125
The answer is to go NT or Windows 2000.

Thanks Merrion!
0
 
LVL 2

Expert Comment

by:Merrion
ID: 9943329
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

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now