[.net] C# and get printer status

Started by
6 comments, last by Main 17 years, 10 months ago
Hi, I need to write a little C# program, that gets status from a specific printer (KIOSK BK-L2163) : Printer OK, not OK, paper stuck, no paper, etc. I've got the full documentation in a pdf file : http://www.yousendit.com/transfer.php?action=download&ufid=879BA4FF048D5A7D with section about getting printer status (section 4.3.4). but I still can't figure it out : which data I need to send in order to get the status information, And how to understand the answer ? Any help will be appreciated, Thank you !
Advertisement
What were the results of your attempts with this thread?
Hi Dave,

The problem in the previous thread is on hold (We are waiting for new drivers).

This is a different printer, driver, and documentation :)
Thanks again.
Doh! That's what I get for assuming. Sorry.
The download link won't work for me.
Hi !

I uploaded the file again. try this please :

http://www.mytempdir.com/811824

http://www.yousendit.com/transfer.php?action=download&ufid=E85130F21BA3391E

Thanks !
Try this little program:
using System;using System.Management;namespace PrinterStatus{    class MainClass    {        [STAThread]        static void Main(string[] args)        {            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");            foreach (ManagementObject printer in searcher.Get())            {                Console.WriteLine(printer["Name"].ToString()+":\n");                foreach (System.Management.PropertyData pData in printer.Properties)                {                    if (pData.Value != null)                    {                        Console.Write(pData.Name + " = ");                        if (!(pData.Value is Array))                            Console.WriteLine(pData.Value.ToString());                        else                        {                            Console.WriteLine();                            foreach (object v in (Array)pData.Value)                                Console.WriteLine("       "+v.ToString());                        }                    }                }                Console.WriteLine("\n\n\n");            }            Console.ReadLine();        }    }}

(You have to add System.Management to the references.)

For each printer you should get something like this:
Canon iP4200:Attributes = 3652AveragePagesPerMinute = 0Capabilities =        4       2       3       5CapabilityDescriptions =        Copies       Color       Duplex       CollateCaption = Canon iP4200CreationClassName = Win32_PrinterDefault = TrueDefaultPriority = 0DetectedErrorState = 0DeviceID = Canon iP4200Direct = FalseDoCompleteFirst = TrueDriverName = Canon iP4200EnableBIDI = TrueEnableDevQueryPrint = FalseExtendedDetectedErrorState = 0ExtendedPrinterStatus = 2Hidden = FalseHorizontalResolution = 4294967293JobCountSinceLastReset = 0KeepPrintedJobs = FalseLocal = TrueName = Canon iP4200Network = FalsePaperSizesSupported =        7       8       23       22       55       1       1       1       1       1       1       1       1       11       1       1       1       1       1       1       1       1       1       1       1PortName = USB001PrinterPaperNames =        Letter       Legal       A5       A4       B5       10x15 4x6in 101.6x152.4mm       4 x 8 Zoll 101,6 x 203,2 mm       13x18 5x7in 127.0x177.8mm       8 x 10 Zoll 203,2 x 254,0 mm       L 89x127mm       2L 127x178mm       Hagaki 100 x 148 mm       Hagaki 2 200 x 148 mm       Umschlag #10       Umschlag DL       Choukei 3 120 x 235 mm       Choukei 4 90 x 205 mm       Youkei 4 105,5 x 235 mm       Youkei 6 98 x 190 mm       Kreditkarte 2,13x3,39 Zoll 54x86       Karte 2,16 x 3,58 Zoll  55 x 91        P 89x254mm       CD-R-Fach C       Benutzerdefiniert...       Square 128 x 128 mmPrinterState = 0PrinterStatus = 3PrintJobDataType = RAWPrintProcessor = Canon iP4200 Print ProcessorPriority = 1Published = FalseQueued = FalseRawOnly = FalseShared = FalseSpoolEnabled = TrueStatus = UnknownSystemCreationClassName = Win32_ComputerSystemSystemName = 7D8791C0VerticalResolution = 4294967293WorkOffline = True


Use something like
If(printer["Name"].ToString()== “KIOSK BK-L2163”)…
To get only the status of that printer.


You need to know what the values of “PrinterStatus“ and “PrinterState” mean, maybe you will find some information in the documentation.
I think(I’m not sure)
PrinterStatus=1 means Other,
2 Unknown,
3 Idle,
4 Printing,
5 Warmup,
6 Stopped printing,
7 Offline.


I hope this was helpful!

[Edited by - Kambiz on July 18, 2006 5:44:13 PM]
Thanks a lot !

But the main problem is :
"You need to know what the values of “PrinterStatus“ and “PrinterState” mean"

:-)

I read the pdf file, which has "Check status" section,
But I couldn't figure out how to do it...

This topic is closed to new replies.

Advertisement