|
This Blog Has Been Moved !This Blog Has been moved to http://aleemkhan.wordpress.com 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 { 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(); } } } Comments
1 comments have been posted.
Posted @ 6:24 AM
2015-12-29keyun
michael kors outlet louis vuitton bags north face fake oakley sunglasses cheap oakley sunglasses michael kors outlet online ugg boots coach factory outlet louis vuitton outlet stores abercrombie michael kors outlet online coach outlet online michael kors outlet tory burch outlet online ed hardy outlet ugg boots louis vuitton purses retro 11 p90x toms outlet michael kors outlet ray ban outlet fitflop clearance the north face jackets michael kors outlet online sale canada goose sale nike free 5.0 air max 95 michael kors outlet canada goose coats ugg boots gucci outlet uggs outlet uggs australia nfl jerseys oakley outlet jordan concords coach outlet store online clearance giuseppe zanotti outlet kids lebron shoes |