Get the current state of the printer in C #

xiaoxiao2021-03-05  23

To get the status of the printer, a union should be defined.

ENUM PrintersTatus {Other Status = 1, Unknown, Idle, Print, Preheating, Stop Print, Print, Offline}

The "printing" and "printing" are the same meaning, as for why this is the case, I don't know.

Add a reference to System.Management in a program: use system.management;

The function of obtaining the printer status is written as follows:

///

/// Get the current status of the printer //// /// Printer device name /// Printer status private PrinterStatus GetPrinterStat (string PrinterDevice) {PrinterStatus ret = 0; string path = @ "win32_printer.DeviceId = '" PrinterDevice "'"; ManagementObject printer = new ManagementObject (path); printer.Get (); ret = (PrinterStatus Convert.TOINT32 (Printer.properties ["PrintersTatus"]. Value); Return Ret;

Call example:

Messagebox.show (Getprinterstat ("192.168.88//samsung scx-4x16 series"). TOSTRING ());

转载请注明原文地址:https://www.9cbs.com/read-34768.html

New Post(0)