Check printer status in .net
Posted by Viral Sarvaiya on August 1, 2011
Hi
Today i get new thing from my current projet, how to check the status of the printer means wether the printer is connected to PC or not.
For that we have to add reference of the “System.Management”
Here it is code for check status of the printer.
using System.Management;
class PrinterOffline
{
private static void Main(string[] args)
{
// Set management scope
ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string printerName = "";
foreach (ManagementObject printer in searcher.Get()) {
printerName = printer("Name").ToString().ToLower();
if (printerName.Equals("Name_Of_Printer")) {
Console.WriteLine("Printer = " + printer("Name"));
if (printer("WorkOffline").ToString().ToLower().Equals("true")) {
// printer is offline by user
Console.WriteLine("Your Plug-N-Play printer is not connected.");
} else {
// printer is not offline
Console.WriteLine("Your Plug-N-Play printer is connected.");
}
}
}
}
}
thanks and enjoy coding…



Kelly's Chronicles said
http://kellyschronicles.wordpress.com/2008/10/09/check-printer-status-with-vb-net
vb.net version of the same code…..
viralsarvaiya said
Dear Kelly’s Chronicles,
I know that, I have copy your post to my blog. My blog is totally for my personal use . its helps me in future so i use your code to my personal blog.
hope u have dont mind for that.
thanks a lot for wonderful code.
Kelly's Chronicles said
That’s fine. Code is code. Glad I could help. God bless and good luck with your blog.
viralsarvaiya said
Thanks for the appreciation dear…
Check SQL Database Exists with C# « Kelly's Chronicles said
[...] Morning! I wanted to give a shout out to another blogger who linked to us yesterday here. It was so nice of him you know? Just amazing, the generosity of some folks out [...]