0

I'm trying to get print jobs details generated from windows (AD based) print server which is serving more than 100s of client machines.

As I need to store some other details along with job details, used FindNextPrinterChangeNotification to get jobId at client(s) & passed that to WMI at server to get more job details.

Please refer both http://www.codeproject.com/Articles/51085/Monitor-jobs-in-a-printer-queue-NET and https://blogs.msdn.microsoft.com/ocleon/2008/03/26/get-print-jobs-using-wmi-and-managmentobjects/

But the thing is I'm getting different ids for same job at both server & client (for example: 29956 & 29).

Can anyone explain how to handle jobids between this two Apis and arrive a solution for this issue.

Edit 1: From domain client machines by connecting the print server (\ipaddress) and executing the FindNextPrinterChangeNotification method, got jobinfo details (jobid 29956). But at the server by executing the select query to wmi win32-printjob class, yields no results at all and what I got previously was clients local print jobid (29).

Can anyone shed some light on how to get job details at print server by executing wmi queries locally.

Murugan Durai
  • 143
  • 3
  • 12
  • "for example: **29**956 & **29**" -- Are those numbers real examples? If so, that's kind of suspicious. Are the first two digits always the same? – Carey Gregory Jul 17 '16 at 05:14
  • Yes. Those are real numbers. 1st two digit of 29XXX are always same and small numbers are varying a lot. Today that small one already reached 7x. Currently am using WMI event listener at client machines, now I could get all the data about print job except page counts. – Murugan Durai Jul 19 '16 at 10:12
  • I would examine my own code very carefully for bugs. That pattern looks suspiciously like a number being corrupted somehow. – Carey Gregory Jul 19 '16 at 14:14
  • Hi @CareyGregory, Thanks for your help. I have double checked my code. When it is running at domain client machine 2 jobids created onle for local machine (29XXX) and the same code running at print server got only one jobid (75). Also do you have any idea about GetJob win32 function, currently am using it for pages count but could not get any result. My code flow is OpenPrinter --> GetJob --> ClosePrinter. – Murugan Durai Jul 20 '16 at 12:53
  • I don't know of any way to get accurate page counts from anywhere except the spool file. That has been a problem with GetJob for a ridiculous number of years now. Microsoft obviously doesn't care to bother fixing it. – Carey Gregory Jul 20 '16 at 13:53
  • Once again, Thanks for clarification about GetJob. Could you please let me know how to get page counts from spool file. I already paused & resumed the printjob using WMI (to get page counts through GetJob). – Murugan Durai Jul 20 '16 at 14:19
  • Can I use ReadPrinter to get pagecounts? http://stackoverflow.com/questions/12866711/how-do-i-find-the-spool-file-for-the-job-with-a-given-id-even-when-spool-file-po – Murugan Durai Jul 20 '16 at 14:40
  • Yes you can. You'll need to parse the file yourself and you'll need to know the format to do that. http://www.undocprint.org/formats/winspool/spl – Carey Gregory Jul 20 '16 at 17:08
  • Thanks a ton @CareyGregory. I will check the ReadPrint function & let you know the results. Also, is it a good idea to use SNMP total print count differences captured between (WMI) paused & resumed printjob like http://www.papercut.com/kb/Main/HowDoesHardwareCheckingAffectPrintingSpeed – Murugan Durai Jul 20 '16 at 17:46
  • Hi @CareyGregory. Does ReadPrinter function itself won't give the data, do I really need do parsing? Do you know how to parse the .spl file with C#? – Murugan Durai Jul 20 '16 at 18:25
  • You should be able to do it in C#, C or C++ since all of them can call the Win32 APIs. How to parse the spool file is a project of its own. It's laid out very much like an EMF file, if you're familiar with those. Anyway, that's not a question someone can answer here. The answer would be hundreds of lines of code. – Carey Gregory Jul 20 '16 at 19:47
  • Hi @CareyGregory, I tried to read the file using www.codeproject.com/Articles/10586/EMF-Printer-Spool-File-Viewer. But I could not catch the file when it was created because the printjob has been already paused & resumed through WMI win32_PRINTJOB's _InstanceDeletionEvent. Always getting exception like 'Could not find file 'C:\Windows\System32\spool\PRINTERS\00085.SPL' Do you have any idea like when we can pause in order to read the spool file? Please suggest. – Murugan Durai Jul 22 '16 at 06:02

0 Answers0