The above method returns the list of printers configured in the local machine. The printer ManagementObject exposes many useful properties. Using the PaperSizesSupported property, we can get the list of paper sizes supported by that particular printer. To view information about Win32_Printer, please refer MSDN.

Using this printer name, we can fetch the print job collection by using the following method:

The query "SELECT * FROM Win32_PrintJob" can also be used as "SELECT * FROM Win32_PrintJob WHERE Name like '"+ printerName.Replace("\", "\\") +"%'". But the query with WHICH attribute caused problems in my system which was running Windows 2000 but ran smooth in Windows XP machines. So currently, I am making a loop through all the print jobs and identify print jobs for that particular printer.

Now, let's see how to manage these print jobs. The print console provided by Windows allows us to Pause, Resume & Cancel print job. It also allows to set priority for a print job. Using WMI, we can perform Pause, Resume & Cancel, but it doesn't provide any method for changing the priority level.

By invoking the Pause method, we can pause the print job. Similar approach is required for resuming the print job. Just we need to invoke the Resume method.

prntJob.InvokeMethod("Resume", null);

Win32_PrintJob WMI_CLASS provides methods to pause and resume a print job. But it doesn't provide any method for canceling the print job. To cancel the print job, you need to just delete the management object.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Hi my service have timer, witch run GetPrintJobsCollection every "x" second. If I set, fore example, 1 second for timer, I recive 4 results records for 1 print job (document with 5 pages). If I set 5 second for timer I didn't recive any result then printing document with 1 page.

Maybe I don't exactly understand how realy use GetPrintJobsCollection function?

I wroting local PC service, with have to collect information about who, when and what printing.

But I need the document physical path. Actually I am developing Virtual Printer Driver so the document I opened and trying to print I need that document Physical path using code. So I can convert that document into byte array and pass it to the application. In real I don't want to print that document but I want to upload that document to the Web server using Virtual Print Driver.

Can anyone tell me the way or property to get the full path of the document. Something like

I am trying to use this code for a program that i am writing. I have it searching out all available printers. now i want it to wait for a print job to start, and then pause the job until someone selects resume or cancel. I understand the pause, resume, and cancel part of my application, but how do i get the application to sit and wait for a job to be present?

Can you please share the code here in Code Project for how you are defining "PrintControl" class and how you using that in your application for fetching Printers and Jobs list for the particular printer? Because I have the same issue here for my application. I posted my questions in many sites also here in code project but I did not get any solution yet.Any help will be appreciated.

If a print job is sent and does not complete (because the printer is turned off, out of paper, etc.), I want to handle the reprint. I do not want Windows to attempt to resend the print job when the printer becomes available.

FYI: Why do we want this? We are printing serial numbers for machines. Our machines *must* have unique serial numbers. Windows spools a print job and may get partially through the job when an error occurs. If the error is resolved, Windows sometimes restarts the print job. Now we have machines with duplicate serial numbers, and that is not good. I have been tasked to prevent this scenario.

Sounds simple and could work. I will to apply your solution, until I find another way.Maybe we can use winspool.drv for receive notifications, if I find something else, I tell you.Thank you for your fast reply.

I have installed snmp provider.I want to get and set sysContact property of SNMP_RFC1213_MIB_system class whose parent class is SnmpMacro for partiucalr local or remote device.I am geting provider not found error. While properites and class under __NAMESPACE can be set and get. Then why I can not set and get class and properties under SnmpMacro? how to do that?

I also have the same problem as Colin Hendricks, I use this method and pause all documents which came to printer, than I analyze them to see I aprouve them or not, and than - finally resume them to print. But even that i tried to make this in a single project, as windows service, with a smaller time as interval. Very often some pages get to printer before I get the chance to pause them.Is there any idea of solving this problem?

Is there any chance of getting a downloadable example of this supposedly simple printer example ( Because I just freshly installed c sharp 2005 express ) and regardless of where I put the code , at least thus far I get a ton of errors and I cant get it to work ( Yes I am new to c sharp and havent used it before )

I write soft for control what document printed.It will be a Windows service application.Your code is very intresting for me.But I need function for count new printing job.Can you help me show how I can do it?

HI auther Thanks for this article . I have a WMI sample in VC++ which enumerates local services ( using //./root/cimv2 input) . But when I try to connect to remote machine the pWbemLocater-->ConnectServer() fails . I am using XP machine and the remote machine is also XP. So I have a user name Dharani and password xxxxx with administrator rights . The same way I set up another user account with the same USer name and password in the remote machine ( Is it necessary to have the same USer name /passwrod at the remote machine ? ) But still the remote connection is not happening . How to solve it ? What r the real previleges needed at the target system ?? could u point it out ??PS : When I try to connect to a system in my IP group - thats if my IP is 210.210.124.xxx and remote machine's IP is 210.210.124.xxy it fails in milliseconds and returns but in case if the remote machine's IP is differing to another layer like 210.210.12x.xfg then the pWbemLocator-->ConnectServer() takes a big 8-9 seconds to return to say it failed !!!! I hope this will be a terrible effect on my C/S design to query WMI machines . any ideas pls ??

I am not pretty sure about the options in VC++. But if you connect to the remote computer using WMI, you need to define ManagementScope. When you define ManagementScope we also define the connect options in which we provide the username and password.

//Connect to the remote computerConnectionOptions co = new ConnectionOptions();

Good Article.I have been writing a similar piece of code recently and have also encountered problems using "SELECT * FROM Win32_PrintJob WHERE Name like '"+ printerName.Replace("\", "\\") +"%'". I have thoroughly searched MSDN and various other sources but have not been able to determine what is causing the problem. I am also having to loop through all of the jobs on the machine to get the right ones but obviously this is inefficient and less than elegant. Would appreciate any extra info on this!