In response to a newsgroup query here is the code needed to view the printer queues on your system. Once again this is achieved using Windows Management Instrumentation or WMI. Note this code will display all printer queues if there are documents waiting to be printed. To test this open up a printer queue and pause the printer then use notepad or word etc and print to the paused printer.
This code has been written on the release version of .NET
- //WMI4.cs
- //Demonstrates how to view printjobs for any given printer
- //Written 05/17/02 By John O'Donnell - [email protected]
- using System;
- using System.Management;
- namespace WMI4 {
- class Class1 {
- static void Main(string[] args) {
- Console.WriteLine("Retrieving printer queue information using WMI");
- Console.WriteLine("==================================");
- //Query printer queue
- System.Management.ObjectQuery oq = new System.Management.ObjectQuery "SELECT * FROM Win32_PrintJob");
- ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
- ManagementObjectCollection queryCollection1 = query1.Get();
- foreach(ManagementObject mo in queryCollection1) {
- Console.WriteLine("Printer Driver : " + mo["DriverName"].ToString());
- Console.WriteLine("Document Name : " + mo["Document"].ToString());
- Console.WriteLine("Document Owner : " + mo["Owner"].ToString());
- Console.WriteLine("==================================");
- }
- }
- }
Ajay BhisePosted May 27, 2014, 8:04 AM
Hi Ahmed... You need to add the System.Management namespace in the project References
ahmedPosted May 9, 2010, 9:53 PM
at the beginning i want to thank you and i have just one question that i need your help in i used this code in the visual studio 2008, bur the IDE didn't recognized the class that i am working with and it bring out an error for e.x "int" imagine that the IDE didn't recognize the "int" type?? this what was happened to me please i need your help if u can and thanks again for this topic
Asif RehmanPosted Dec 20, 2009, 11:57 PM
Hello... i have seen ur easy to understand articles releted to printing process...i would be thankful if u can solve one more problem...\ I want to print instantly printing like ECG... i.e. a single pulse sent to the printer and it prints without ejecting the paper and when it recieves another short pulse it prints ahead of the previous pulse... how can i do this...i guess print controller can do that but i m not been able to handle it properly... i would wait for ur reply...
Dhanushka HerathePosted May 31, 2009, 12:54 AM
Hi I want to get the copy count, Duplex and paper Type of the print job.. Using above management object please explain me how to get those details.. Thank you
IgorPosted Jan 28, 2008, 4:47 AM
Hi! Thanks! But what can i do if printer is network? Regards, Igor