Hey,
I just got a mail from one of the friends, he wants to get the information about the printer like printer status, error, current status etc, I thought I should share the answer with all.
Yes there are ways to do this, the most common answer to almost anything related to any information in Windows is
WMI (Windows Management Instrumentation), this is the layer windows provides and uses for retrieving all sorts of information from the system and the running kernel.
In the following code I have listed all your printers on the system and also some of their properties/status like printing, stopped etc, but I can’t possibly list everything.
There is tons of information you can get about printer using WMI Win32_Printer class. Please refer to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp and modify this code according to what you actually need.
using System;
using System.Diagnostics;
using System.Management;
using System.ComponentModel;
namespace ConsoleWMI
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
new Class1();
}
public Class1()
{
System.Management.ManagementObjectSearcher searcher = new ManagementObjectSearcher
(“SELECT * FROM Win32_Printer”);
foreach (ManagementObject service in searcher.Get())
{
string [] pStatus = {“Other”,”Unknown”,”Idle”,”Printing”,”WarmUp”,”Stopped Printing”, “Offline”};
string [] pState = {“Paused”,”Error”,”Pending Deletion”,”Paper Jam”,”Paper Out”,”Manual Feed”,”Paper Problem”,
“Offline”,”IO Active”,”Busy”,”Printing”,”Output Bin Full”,”Not Available”,”Waiting”,
“Processing”,”Initialization”,”Warming Up”,”Toner Low”,”No Toner”,”Page Punt”,
“User Intervention Required”,”Out of Memory”,”Door Open”,”Server_Unknown”,”Power Save”};
foreach(System.Management.PropertyData pData in service.Properties)
{
if(pData.Name == “Caption” || pData.Name == “Default” || pData.Name==”ServerName”)
Console.WriteLine(pData.Name + ” = ” + pData.Value);
else if(pData.Name == “PrinterState”)
Console.WriteLine(pData.Name + ” = ” + pState[Convert.ToInt32(pData.Value)]);
else if(pData.Name == “PrinterStatus”)
Console.WriteLine(pData.Name + ” = ” + pStatus[Convert.ToInt32(pData.Value)]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Hi,
I want to retreive the status of printer connected in a network which is a usb printer.i have created a windows service which runs and generates reports for the customer and then prints.but if the printer is not ready or not connected then it should not generate the report and the reason should be told to the customer abt the printer.
can i get the code for this in c#.net??
Thanking You
comment – map2
hello, i want to get the copy of the page the printer is printing… like i am printing 5 copies of this page, how do i get the counter that will count if the current printing job is “Copy 1 of 5”, “Copy 2 of 5” and so on, tnx
Is there any way to get the printer manufacturer(make) using WMI
I have a problem, i hope you can help with it.
I use the fuction that you give but i dont kwon how it reale works.
the state of the printer sometimes send 1024, 1025 just when a send a print job and i remove the paper on the printer. The state dont send a value if a idont send a print job, is that ok ??
and also send values unspected.
i hope you can give a help with a state of the printer.
Report printing to network printer should work without specific drivers
is it possible
hello, How do I get information of USB device ?
The style of writing is quite familiar . Did you write guest posts for other blogs?
Nice blog about printer. I have a lot of problem with my office printer. I’m IT support and need to solve any problem. Do you have any suggestion about printer troushooting guide site? Thank you very much.
Hi,
Can i get the sample in vc++ instead of .net? Any help is appreciated.
Thanks
Inar
could you please tell me how can i get the owner document ip if that owner is one of network machines
when i search using win32_printerjob and viwe the owner filed it is appear “Guest” and i want to know the ip address of that guest
Please add a other string at index 0 on both arrays because your error / status codes are indexed from 1 and not 0.
Good post. Hope to read much more great posts in the near future.
I am regular visitor, how are you everybody? This
post posted at this web site is really good.