C # obtain the printer status

Source: Internet
Author: User
Public static string GetPrinterStatus (string PrinterName) {int intValue = GetPrinterStatusInt (PrinterName); string strRet = string. empty; switch (intValue) {case 0: strRet = "Ready (Ready)"; break; case 0x00000200: strRet = "Busy (Busy)"; break; case 0x00400000: strRet = "Printer Door Open"; break; case 0x00000002: strRet = "Printer Error"; break; case 0x0008000: strRet = "initialization (Initializing)"; break; case 0x00000100: strRet = "input, output (I/O Active)"; break; case 0x00000020: strRet = "Manual Feed"; break; case 0x00040000: strRet = "No Toner (No Toner)"; break; case 0x00001000: strRet = "Not Available"; break; case 0x00000080: strRet = "offline (Off Line)"; break; case 0x00200000: strRet = "Out of Memory"; break; case 0x00000800: strRet = "Output port Full"; break; case 0x00080000: strRet = "Current Page cannot be printed (Page Punt)"; break; case 0x00000008: strRet = "Paper Jam"; break; case 0x00000010: strRet = "Paper Out"; break; case 0x00000040: strRet = "Page Problem"; break; case 0x00000001: strRet = "Paused"; break; case 0x00000004: strRet = "Pending Deletion"; break; case 0x00000400: strRet = "Printing"; break; case 0x00004000: strRet = "Processing"; break; case 0x00020000: strRet = "Toner Low"; break; case 0x00100000: strRet = "User Intervention required"; break; case 0x20000000: strRet = "Waiting"; break; case 0x00010000: strRet = "warm Up"; break; default: strRet = "Unknown Status (Unknown Status) "; break;} return strRet;} internal static int GetPrinterStatusInt (string PrinterName) {int intRet = 0; IntPtr hPrinter; structPrinterDefaults defaults = new structPrinterDefaults (); if (OpenPrinter (PrinterName, out hPrinter, ref defaults) {int cbNeeded = 0; bool bolRet = GetPrinter (hPrinter, 2, IntPtr. zero, 0, out cbNeeded); if (cbNeeded> 0) {IntPtr pAddr = Marshal. allocHGlobal (int) cbNeeded); bolRet = GetPrinter (hPrinter, 2, pAddr, cbNeeded, out cbNeeded); if (bolRet) {PRINTER_INFO_2 Info2 = new PRINTER_INFO_2 (); info2 = (PRINTER_INFO_2) Marshal. ptrToStructure (pAddr, typeof (PRINTER_INFO_2); intRet = System. convert. toInt32 (Info2.Status);} Marshal. freeHGlobal (pAddr);} ClosePrinter (hPrinter);} return intRet;} [StructLayout (LayoutKind. sequential, CharSet = CharSet. auto)] internal struct structPrinterDefaults {[financialas (UnmanagedType. LPTStr)] public String pDatatype; public IntPtr pDevMode; [financialas (UnmanagedType. i4)] public int DesiredAccess;}; Status enumeration [FlagsAttribute] internal enum PrinterStatus {PRINTER_STATUS_BUSY = 0x00000200, PRINTER_STATUS_DOOR_OPEN = 0x00400000, PRINTER_STATUS_ERROR = 0x00000002, PRINTER_STATUS_INITIALIZING = 0x00008000, PRINTER_STATUS_IO_ACTIVE = 0x00000100, PRINTER_STATUS_MANUAL_FEED = 0x00000020, latency = 0x00040000, latency = 0x00001000, PRINTER_STATUS_OFFLINE = 0x00000080, latency = 0x00200000, latency = 0x00000800, PRINTER_STATUS_PAGE_PUNT = 0x00080000, PRINTER_STATUS_PAPER_JAM = 0x00000008, PRINTER_STATUS_PAPER_OUT = 0x00000010, latency = 0x00000040, PRINTER_STATUS_PAUSED = 0x00000001, latency = 0x00000004, PRINTER_STATUS_PRINTING = 0x00000400, PRINTER_STATUS_PROCESSING = 0x00004000, PRINTER_STATUS_TONER_LOW = 0x00020000, latency = 0x00100000, PRINTER_STATUS_WAITING = 0x20000000, PRINTER_STATUS_WARMING_UP = 0x00010000}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.