C# Попытка получить состояние принтера в автономном режиме - PullRequest
0 голосов
/ 18 февраля 2020

Мне нужно получить статус принтера, когда он находится в автономном режиме, ниже показано, как я получаю статус;

 // 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();
                    if (printerName.Equals(@"TEC B-EV4-T"))
                    {
                        //Console.WriteLine("Printer = " + printer["Name"]);
                        if (printer.Properties["PrinterStatus"].Value.ToString() == "7")
                        {
                            // printer is offline by user
                            MessageBox.Show("TEC B-EV4-T is offline");
                        }
                        else
                        {
                            // printer is not offline 
                            //Check API first then print
                            ReportDocument cryRpt = new ReportDocument();
                            cryRpt.Load(Environment.CurrentDirectory + "\\Report.rpt");

                            dialog.PrintQueue = new PrintQueue(new PrintServer(), "TEC B-EV4-T");

                            //to the data table here
                            //To data table
                            DataTable dt = ToDataTable(lotinstruct);

                            cryRpt.SetDataSource(dt);

                            cryRpt.PrintToPrinter(1, true, 0, 0);

                            //}

                            MessageBox.Show("Already save result please check label!");
                        }
                    }
                }

Проблема здесь, если (printer.Properties ["PrinterStatus"]. Value. ToString () == "7") кажется, что состояние принтера всегда равно 3, когда я отлаживаюсь (состояние принтера 3 означает, что он находится в режиме ожидания, 7 означает, что он отключен). Есть ли способ узнать, находится ли принтер TE C B-EV4-T в автономном режиме?

1 Ответ

0 голосов
/ 18 февраля 2020

Вы можете сослаться на PrintQueue во встроенном. Net каркасе для проверки состояния принтера. Есть много свойств, чтобы проверить другой статус:

string printerName = "TEC B-EV4-T";
var server = new LocalPrintServer();
PrintQueue queue = server.GetPrintQueue(printerName , Array.Empty<string>()); 
bool isOffline = queue.IsOffline;
bool isBusy = queue.IsBusy;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...