Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Intercepting print jobs by hooking createDCW and createDCA

Posted on 2006-06-09
3
Medium Priority
?
1,222 Views
Last Modified: 2013-12-03
I have been trying to implement password protected printing by hooking createDCW and createDCA and either ‘doing nothing’ or passing the call onto the OS depending on whether the correct password has been entered.

‘doing nothing’ appeared to work, and prevent printing, for applications like Notepad, but caused problems with apps like MS Excel which would get stuck in a loop showing an error.

So in the hook I tried returning NULL, the value returned by createDCW and createDCA if they fail. This caused MS Excel to simply close after trying to print.

I then tried repeating the createDCW/ createDCA as normal, but following it with an AbortDoc, but this seems to allow the print job to get to the print queue, even though abortdoc returns 1.

Any suggestions to what is going wrong?
0
Comment
Question by:PeteMulford
[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
  • 2
3 Comments
 
LVL 3

Expert Comment

by:Mikeh926
ID: 16886192
It sounds like Excel just can't handle the NULL returned from CreateDC. You really need to not change any return codes from the API so that applications think that everything is ok.

Can I suggest that you hook EndDoc()? Return a value that indicates success to the application, but if you want to prevent printing call AbortDoc() from inside your hook.

Mike.
0
 

Author Comment

by:PeteMulford
ID: 16893176
so allow the startdoc, startpage stuff to be sent, but when the enddoc is sent send an abortdoc as well?
0
 
LVL 3

Accepted Solution

by:
Mikeh926 earned 2000 total points
ID: 16893196
Yes, allow the app to think that it's printed.

In your EndDoc() hook, call AbortDoc() and do not call the original EndDoc(). Instead just return the code for success to the app. The app will think it's printed, so no error messages will be displayed, but you can abort the print job.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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