Exemplo n.º 1
0
        public object GetPrinters()
        {
            var resultado = new List <object>();
            //foreach (var NombrePrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            //{
            //    resultado.Add(new { DisplayText = NombrePrinter, Value = NombrePrinter });
            //}

            var server  = new PrintServer();
            var locales = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });

            foreach (var printer in locales)
            {
                resultado.Add(new { DisplayText = printer.FullName, Value = printer.FullName });
            }
            var compartidos = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Shared, EnumeratedPrintQueueTypes.Connections });

            foreach (var printer in locales)
            {
                if (locales.SingleOrDefault(s => s.FullName == printer.FullName) == null)
                {
                    resultado.Add(new { DisplayText = printer.FullName, Value = printer.FullName });
                }
            }

            return(new { Result = "OK", Options = resultado });
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            checkedListBoxPrinters.Width  = splitContainer1.Panel1.Width;
            checkedListBoxPrinters.Height = splitContainer1.Panel1.Height - checkedListBoxPrinters.Top;
            listBoxPrinters.Width         = splitContainer1.Panel2.Width;
            listBoxPrinters.Height        = splitContainer1.Panel2.Height - listBoxPrinters.Top;

            PrintServer          ps  = new PrintServer();
            PrintQueueCollection pqs = ps.GetPrintQueues();

            foreach (PrintQueue pq in pqs)
            {
                if (pq.IsXpsDevice)
                {
                    listBoxPrinters.Items.Add(pq.Name + " (XPSデバイス)");
                }
                else if (pq.QueuePrintProcessor.Name == "mariaprint")
                {
                    int i = checkedListBoxPrinters.Items.Add(pq.Name);
                    checkedListBoxPrinters.SetItemChecked(i, true);
                }

                /*
                 * else if (pq.QueuePrintProcessor.Name != "winprint")
                 * {
                 *  listBoxPrinters.Items.Add(pq.Name + " (独自プリントプロセッサ)");
                 * }
                 */
                else
                {
                    checkedListBoxPrinters.Items.Add(pq.Name);
                }
            }
        }
Exemplo n.º 3
0
    private static PrintQueue GetMicrosoftPdfPrintQueue()
    {
        PrintQueue pdfPrintQueue = null;

        try
        {
            using (var printServer = new PrintServer())
            {
                var flags = new[] { EnumeratedPrintQueueTypes.Local };
                pdfPrintQueue = printServer.GetPrintQueues(flags).SingleOrDefault(lq => lq.QueueDriver.Name == PdfPrinterDriveName);
            }
            if (pdfPrintQueue == null)
            {
                throw new Exception($"Could not find printer with driver name: {PdfPrinterDriveName}");
            }
            if (!pdfPrintQueue.IsXpsDevice)
            {
                throw new Exception($"PrintQueue '{pdfPrintQueue.Name}' does not understand XPS page description language.");
            }
            return(pdfPrintQueue);
        }
        catch
        {
            pdfPrintQueue?.Dispose();
            throw;
        }
    }
        public List <uJob> PrinterQueueView()
        {
            List <uJob> printJobs = new List <uJob>();

            try
            {
                PrintServer          printServer = new PrintServer();
                PrintQueueCollection printQueues = printServer.GetPrintQueues();

                foreach (PrintQueue pq in printQueues)
                {
                    if (pq.NumberOfJobs > 0)
                    {
                        pq.Refresh();
                        PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();

                        foreach (PrintSystemJobInfo job in jobs)
                        {
                            uJob printJob = new uJob(job.Name, $"{pq.Name} | {job.JobName} | {job.JobIdentifier}");
                            printJobs.Add(printJob);
                        }
                    }
                }
            }
            catch (Exception)
            {
                uJob printJob = new uJob("Print Spooler Service", $"An error occurred while loading the Print Jobs.");
                printJobs.Add(printJob);
            }

            return(printJobs);
        }
Exemplo n.º 5
0
            private static PrintQueue GetMicrosoftPdfPrintQueue()
            {
                PrintQueue pdfPrintQueue = null;

                try
                {
                    using (var printServer = new PrintServer())
                    {
                        var flags = new[] { EnumeratedPrintQueueTypes.Local };
                        // FirstOrDefault because it's possible for there to be multiple PDF printers with the same driver name (though unusual)
                        // To get a specific printer, search by FullName property instead (note that in Windows, queue name can be changed)
                        pdfPrintQueue = printServer.GetPrintQueues(flags)
                                        .FirstOrDefault(lq => lq.QueueDriver.Name == PdfPrinterDriveName);
                    }

                    if (pdfPrintQueue == null)
                    {
                        throw new Exception($"Could not find printer with driver name: {PdfPrinterDriveName}");
                    }

                    if (!pdfPrintQueue.IsXpsDevice)
                    {
                        throw new Exception(
                                  $"PrintQueue '{pdfPrintQueue.Name}' does not understand XPS page description language.");
                    }

                    return(pdfPrintQueue);
                }
                catch
                {
                    pdfPrintQueue?.Dispose();
                    throw;
                }
            }
Exemplo n.º 6
0
        private void btnLoadQueues_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            var jobList = String.Empty;

            var server = new PrintServer();
            var queues = server.GetPrintQueues();

            foreach (PrintQueue pq in queues)
            {
                pq.Refresh();
                PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();
                foreach (PrintSystemJobInfo job in jobs)
                {
                    // Since the user may not be able to articulate which job is problematic,
                    // present information about each job the user has submitted.

                    jobList = jobList + "\nServer:\r\n";
                    jobList = jobList + "\n\tQueue:" + pq.Name;
                    jobList = jobList + "\n\tLocation:" + pq.Location;
                    jobList = jobList + "\n\t\tJob: " + job.JobName + " ID: " + job.JobIdentifier;
                } // end for each print job
            }     // end for each print queue
            txtStatus.Text = jobList;
            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Start watching print events
 /// </summary>
 public void Start()
 {
     lock (accesslock)
     {
         if (!isRunning)
         {
             Task.Factory.StartNew(() =>
             {
                 isRunning   = true;
                 printers    = new ArrayList();
                 printServer = new PrintServer();
                 foreach (var pq in printServer.GetPrintQueues())
                 {
                     var pqm = new PrintQueueHook(pq.Name);
                     pqm.OnJobStatusChange += pqm_OnJobStatusChange;
                     pqm.Start();
                     printers.Add(pqm);
                 }
             },
                                   CancellationToken.None,
                                   TaskCreationOptions.None,
                                   factory.GetTaskScheduler()).Wait();
         }
     }
 }
Exemplo n.º 8
0
        /// PrinterStatus
        #region PrinterStatus

        /// <summary>
        /// Gets printer status of the specified printer
        /// </summary>
        /// <param name="printerName">printer name</param>
        /// <returns>printer status</returns>
        public static PrinterTrouble GetPrinterStatus(string host, string printerName, out string statusReport)
        {
            statusReport = "";
            PrinterTrouble printerTrouble = PrinterTrouble.None;

            try
            {
                PrintServer          printServer = new PrintServer(@"\\" + host);
                PrintQueueCollection printQueues = printServer.GetPrintQueues();
                foreach (PrintQueue pq in printQueues)
                {
                    if (pq.Name == printerName)
                    {
                        printerTrouble = SpotPrinterTroubles(ref statusReport, pq);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
            }

            return(printerTrouble);
        }
Exemplo n.º 9
0
        private void init_combo_size()
        {
            //PaperSize pkSize;
            //for (int i = 0; i < printSettings.PaperSizes.Count; i++)
            //{
            //    pkSize = printSettings.PaperSizes[i];
            //    this.selected_parper.Items.Add(pkSize);
            //}

            PrintServer          myPS          = new PrintServer();
            PrintQueueCollection myPrintQueues = myPS.GetPrintQueues();

            int check_print = 0;

            foreach (PrintQueue pq in myPrintQueues)
            {
                pq.Refresh();
                string temp = "";
                //check_print = this.SpotTroubleUsingProperties(ref temp, pq);
                //if (check_print == 0 && !pq.IsOffline)
                if (!pq.IsOffline)
                {
                    this.checkedList_mayin.Items.Add(pq.FullName, false);
                }
            }// end for each print queue
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get the model name of printer.
        /// </summary>
        /// <returns>
        /// If success, return the name of printer driver, otherwise, return empty string.
        /// </returns>
        public static bool GetPrinterDrvName(
            string strPrinterName, ref string strDrvName
            )
        {
            strDrvName = "";
            bool bSuccess = false;

            try
            {
                PrintServer          myPrintServer = new PrintServer(null);
                PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
                foreach (PrintQueue pq in myPrintQueues)
                {
                    if (strPrinterName == pq.Name)
                    {
                        strDrvName = pq.QueueDriver.Name;
                        bSuccess   = true;
                        break;
                    }
                }
            }
            catch
            {
            }

            return(bSuccess);
        }
Exemplo n.º 11
0
        private void BwPerformPrint(object sender, DoWorkEventArgs e)
        {
            var ps = new PrintServer();
            PrintQueueCollection myPrintQueues = ps.GetPrintQueues();

            //Lấy máy in để xử lý trạng thái

            try
            {
                while (dtPrintingStatus.Rows.Count > 0)
                {
                    PrintQueue printer =
                        (from m in myPrintQueues
                         where m.Name.Equals(dtPrintingStatus.Rows[0]["PrinterName"].ToString())
                         select m).FirstOrDefault();
                    if (CheckPrinterStatus(printer))
                    {
                        PerformPrint();
                    }
                    else
                    {
                        //Dừng 4s rồi tiếp tục kiểm tra việc in
                        Thread.Sleep(4000);
                    }
                }
                dsPrinting.Clear();
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(ex.Message);
            }
        }
Exemplo n.º 12
0
        /// <summary> Get the support printer list.  </summary>
        /// <param name="listPrinters">Used to store the supported printers.</param>
        /// <returns> None. </returns>
        /// <remarks> If the port of printer isn't support, the printer will
        /// not store in the list. The printer in the list were sorted by
        /// name. The default printer will be the 1st element, if it is in the
        /// list.  </remarks>
        public static void GetSupportPrinters(List <string> listPrinters)
        {
            listPrinters.Clear();

            try
            {
                // If spooler was stopped, new PrintServer( null ) will throw
                // a exception.

                string strDefPrinter = "";

                PrinterSettings      settings      = new PrinterSettings();
                PrintServer          myPrintServer = new PrintServer(null);
                PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
                foreach (PrintQueue pq in myPrintQueues)
                {
                    PrintDriver queuedrv = pq.QueueDriver;
                    if (IsSupportPrinter(queuedrv.Name) == true)
                    {
                        if (EnumPortType.PT_UNKNOWN != (EnumPortType)dll.CheckPortAPI(pq.Name))
                        {
                            listPrinters.Add(pq.Name);
                        }
                    }
                    settings.PrinterName = pq.Name;
                    if (settings.IsDefaultPrinter)
                    {
                        strDefPrinter = pq.Name;
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 13
0
        private List <SelectListItem> GetPrinters()
        {
            List <SelectListItem> list = new List <SelectListItem>();

            int i = 1;

            using (var printServer = new PrintServer(string.Format(@"\\{0}", "D-CASSASV900")))
            {
                foreach (var queue in printServer.GetPrintQueues())
                {
                    list.Add(new SelectListItem {
                        Text = queue.FullName, Value = i.ToString()
                    });
                }
            }

            using (var printServer = new PrintServer(string.Format(@"\\{0}", "S-CASSASV06")))
            {
                foreach (var queue in printServer.GetPrintQueues())
                {
                    list.Add(new SelectListItem {
                        Text = queue.FullName, Value = i.ToString()
                    });
                }
            }

            return(list);
        }
Exemplo n.º 14
0
        private static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                // Console.WriteLine("L");
                PrintServer ps = new PrintServer();
                // PrintServer ps = new PrintServer(System.Printing.PrintSystemDesiredAccess.AdministrateServer);
                // PrintQueueCollection pQueue = ps.GetPrintQueues();
                PrintQueueCollection pQueue = ps.GetPrintQueues();
                // new PrintQueue(ps, printer.printer_name, PrintSystemDesiredAccess.AdministratePrinter)
                int x = 1;
                foreach (PrintQueue pq in pQueue)
                {
                    //  Console.WriteLine(pq.Name);

                    foreach (var job in ps.GetPrintQueue(pq.Name).GetPrintJobInfoCollection())
                    {
                        job.Pause();
                        // Console.WriteLine("Paused - " + job.Name);
                    }
                    //  Console.WriteLine("----");
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 15
0
        // GET: PrintServer
        public ActionResult Index()
        {
            List <MyPrintServer> myPrintServers = new List <MyPrintServer>();

            foreach (var server in Support.GetAllPrintServers())
            {
                string printerCount;
                string ipAddress;
                try
                {
                    PrintServer printServer = new PrintServer(@"\\" + server, PrintSystemDesiredAccess.AdministrateServer);
                    printerCount = printServer.GetPrintQueues().Count().ToString();
                }
                catch
                {
                    printerCount = "N/A";
                }

                try
                {
                    ipAddress = Dns.GetHostEntry(server).AddressList[0].ToString();
                }
                catch
                {
                    ipAddress = "N/A";
                }

                myPrintServers.Add(new MyPrintServer {
                    Name = server.ToString(), PrinterCount = printerCount, IP = ipAddress
                });
            }
            return(View(myPrintServers.OrderBy(o => o.Name)));
        }
Exemplo n.º 16
0
        private void PrintingPreviewWindow_Loaded(object sender, RoutedEventArgs e)
        {
            List <Printer> printers = new List <Printer>();

            PrintServer          printServer = new PrintServer();
            PrintQueueCollection printQueues = printServer.GetPrintQueues();
            string  defaultFullName          = LocalPrintServer.GetDefaultPrintQueue().FullName;
            Printer defaultPrinter           = null;

            foreach (PrintQueue printQueue in printQueues)
            {
                Printer printer = new Printer(printQueue);
                printers.Add(printer);
                if (printer.FullName == defaultFullName)
                {
                    defaultPrinter = printer;
                }
            }

            printers.Reverse();

            PrintersCombo.ItemsSource = printers;

            PrintersCombo.SelectionChanged -= PrintersCombo_SelectionChanged;
            PrintersCombo.SelectionChanged += PrintersCombo_SelectionChanged;

            if (defaultPrinter != null)
            {
                PrintersCombo.SelectedItem = defaultPrinter;
            }
            else
            {
                PrintersCombo.SelectedIndex = 0;
            }
        }
Exemplo n.º 17
0
        public SettingsWindow()
        {
            InitializeComponent();
            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            var serv    = new PrintServer();
            var printer = serv.GetPrintQueues();

            foreach (var s in printer)
            {
                PrinterComboBox.Items.Add(s.Name);
            }
            cams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            foreach (FilterInfo c in cams)
            {
                CameraComboBox.Items.Add(c.Name);
            }
            TopMarginTextBox.Text       = Settings.TopMargin.ToString();
            CountDownTextBox.Text       = Settings.WaitTimeInSeconds.ToString();
            SideMarginTextBox.Text      = Settings.SideMargin.ToString();
            ImageGapTextBox.Text        = Settings.ImageGap.ToString();
            PrinterComboBox.Text        = Settings.PrinterName;
            BackgroundImageTextBox.Text = Settings.BackgroundImagePath;
            SaveFolderTextBox.Text      = Settings.SaveFolder;
            CameraComboBox.Text         = Settings.CameraName;
            TestModeCheckBox.IsChecked  = Settings.TestMode;
        }
Exemplo n.º 18
0
        private void BwPerformPrint(object sender, DoWorkEventArgs e)
        {
            var ps = new PrintServer();
            PrintQueueCollection myPrintQueues = ps.GetPrintQueues();
            //Lấy máy in để xử lý trạng thái

            try
            {
                while (dtPrintingStatus.Rows.Count > 0)
                {
                    PrintQueue printer =
                        (from m in myPrintQueues
                         where m.Name.Equals(dtPrintingStatus.Rows[0]["PrinterName"].ToString())
                         select m).FirstOrDefault();
                    if (CheckPrinterStatus(printer))
                    {
                        PerformPrint();
                    }
                    else
                    {
                        //Dừng 4s rồi tiếp tục kiểm tra việc in
                        Thread.Sleep(4000);
                    }
                }
                dsPrinting.Clear();
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(ex.Message);
            }
        }
Exemplo n.º 19
0
        public void Refresh()
        {
            setSpoolerStatus();
            string deFaultPrinter = GetDefaultPrinter();

            Application.Current.Properties["dp"] = deFaultPrinter;
            defaultPrinter.Text       = deFaultPrinter;
            defaultPrinter.Foreground = new SolidColorBrush(Colors.Green);
            string dp = Application.Current.Properties["dp"].ToString();

            PrintServer myPrintServer = new PrintServer(dp);
            // List the print server's queues
            PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
            String printQueueNames             = "My Print Queues:\n\n";

            noj.Text = GetNumberOfPrintJobs(deFaultPrinter).ToString();
            foreach (string printer in PrinterSettings.InstalledPrinters)
            {
                this.cboPrinter.Items.Add(printer.ToString());
                PrinterSettings p = new PrinterSettings();
                p.PrinterName = printer;
                if (p.IsDefaultPrinter)
                {
                    cboPrinter.Text = printer.ToString();
                }
            }
        }
Exemplo n.º 20
0
        private void buttonShowJobs_Click(object sender, EventArgs e)
        {
            try
            {
                string               psName       = "";
                PrintServer          _ps          = new PrintServer();//(@"\\" + psName);
                PrintQueueCollection _psAllQueues = _ps.GetPrintQueues();

                StringBuilder prnStr = new StringBuilder();


                foreach (PrintQueue pq in _psAllQueues)
                {
                    try
                    {
                        pq.Refresh();
                        //_pq.IsProcessing();

                        PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();
                        foreach (PrintSystemJobInfo job in jobs)
                        {
                            prnStr.Append("\r\n");
                            prnStr.Append(pq.Name);
                            prnStr.Append(" : ");
                            prnStr.Append(pq.Location);
                            prnStr.Append("\r\n");
                            prnStr.Append(job.JobName);
                            prnStr.Append(" ID: ");
                            prnStr.Append(job.JobIdentifier);
                            prnStr.Append(" ID: ");
                            prnStr.Append(job.NumberOfPagesPrinted);
                            prnStr.Append("/");
                            prnStr.Append(job.NumberOfPages);
                            prnStr.Append(" st:");
                            prnStr.Append(job.JobStatus.ToString());
                            prnStr.Append("\r\n-------------------------------------\r\n");
                        }
                    }
                    catch (Exception ex)
                    {
                        string sEvent = pq.Name + " : " + ex.Message;
                    }
                }

                string jobList = prnStr.ToString();
                if (string.IsNullOrEmpty(jobList))
                {
                    this.textBox1.Text = "No job in queue.";
                }
                else
                {
                    this.textBox1.Text = jobList;
                }
            }
            catch (System.Exception ex)
            {
                this.textBox1.Text = ex.Message;
            }
        }
Exemplo n.º 21
0
        private static List <PrintQueue> GetAllPrinters()
        {
            var server                 = new PrintServer();
            var printQueues            = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
            List <PrintQueue> allVKP80 = printQueues?.Where(x => x.FullName.ToLower().Contains(PrinterName))?.ToList();

            return(allVKP80);
        }
Exemplo n.º 22
0
        private bool checkPrintSuccess(string docName)
        {
            bool        success       = false;
            PrintServer myPrintServer = new PrintServer();

            // List the print server's queues
            PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
            String printQueueNames             = "My Print Queues:\n\n";
            string printJob = "JOBS:\n\n";


            foreach (PrintQueue pq in myPrintQueues)
            {
                printQueueNames += "\t" + pq.Name + "\n";

                //HP LaserJet Pro MFP M127fw

                if (pq.Name == "HP LaserJet Pro MFP M127fw")
                {
                    try
                    {
                        PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();


                        if (jobs != null)
                        {
                            foreach (PrintSystemJobInfo job in jobs)
                            {
                                printJob += "\t" + job.Name + "\n";

                                if (job.Name == docName && (((job.JobStatus & PrintJobStatus.Completed) == PrintJobStatus.Completed) || ((job.JobStatus & PrintJobStatus.Printed) == PrintJobStatus.Printed)))
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }// end for each print job
                        }
                    }
                    catch (NullReferenceException e)
                    {
                        success = true;
                    }

                    break;
                }
            }
            Console.WriteLine(printQueueNames);

            MessageBox.Show(printJob);
            Console.WriteLine("\nPress Return to continue.");
            Console.ReadLine();

            return(success);
        }
Exemplo n.º 23
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            PrintServer ps = new PrintServer();

            foreach (PrintQueue pq in ps.GetPrintQueues())
            {
                cmbPrinters.Items.Add(pq.Name);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Llena los combos con las impresoras instaladas en la computadora
        /// </summary>
        /// <history>
        /// [lchairez] 05/Feb/2016 Created
        /// </history>
        private void FillPrinters()
        {
            PrintServer server = new PrintServer();

            foreach (PrintQueue queue in server.GetPrintQueues())
            {
                cmbPrinterInvitation.Items.Add(queue.FullName);
                cmbPrinterMeal.Items.Add(queue.FullName);
            }
        }
Exemplo n.º 25
0
        public static void LimparFila()
        {
            var ps     = new PrintServer();
            var queues = ps.GetPrintQueues();

            foreach (PrintQueue pq in ps.GetPrintQueues())
            {
                //sempre chamar o refresh antes do getPrintJobInfo...
                pq.Refresh();
                if (pq.GetPrintJobInfoCollection() != null)
                {
                    var jobs = pq.GetPrintJobInfoCollection();
                    foreach (var job in jobs)
                    {
                        job.Cancel();
                    }
                }
            }
        }
Exemplo n.º 26
0
        private PrintQueueCollection listSharedPrinters()
        {
            PrintServer          printServer = new PrintServer();
            PrintQueueCollection printQueues = printServer.GetPrintQueues(new[]
            {
                EnumeratedPrintQueueTypes.Local,
                EnumeratedPrintQueueTypes.Connections
            });

            return(printQueues);
        }
Exemplo n.º 27
0
 private PrintQueue GetPrintQueue(string printerName)
 {
     using (var printServer = new PrintServer())
     {
         // GetPrintQueue(queueName) might not work with some types of network printers,
         // but giving the queue description strangely works, but this is not a safe solution.
         // Instead we just get all queues and filter them, that always works.
         var queues = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
         return(queues.SingleOrDefault(pq => pq.FullName == printerName));
     }
 }
Exemplo n.º 28
0
        List <PrintQueue> GetPrinters()
        {
            PrintServer localPrintServer = new PrintServer();

            PrintQueueCollection printQueues = localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });

            var printerList = (from printer in printQueues select printer).ToList();

            return(printerList);

            //from --> http://www.mindfiresolutions.com/How-to-get-list-of-Local-and-Network-Printers-1495.php
        }
Exemplo n.º 29
0
 public List <Printer> GetAllPrinters()
 {
     using (var printServer = new PrintServer())
     {
         using (var printQueues = printServer.GetPrintQueues())
         {
             return(printQueues.Select(p => new Printer {
                 Name = p.FullName
             }).ToList());
         }
     }
 }
Exemplo n.º 30
0
        static public List <PrintQueue> GetPrintersWithPrintQueueClass(string server)
        {
            PrintServer       printServer   = new PrintServer(server);
            var               myPrintQueues = printServer.GetPrintQueues().OrderBy(t => t.Name);
            List <PrintQueue> printerList   = new List <PrintQueue>();

            foreach (PrintQueue pq in myPrintQueues)
            {
                pq.Refresh();
                printerList.Add(pq);
            }
            return(printerList);
        }
Exemplo n.º 31
0
        private PrintQueue FindPrintQueueByName(string name)
        {
            PrintServer server = new PrintServer();
            foreach (PrintQueue queue in server.GetPrintQueues(new EnumeratedPrintQueueTypes[] { EnumeratedPrintQueueTypes.Connections, EnumeratedPrintQueueTypes.Local }))
            {
                if (queue.Name == name)
                {
                    return queue;
                }
            }

            return null;
        }
Exemplo n.º 32
0
        private List <string> getPrinter()
        {
            List <string> printersList = new List <string>();
            var           server       = new PrintServer();
            var           queues       = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local });

            foreach (var queue in queues)
            {
                printersList.Add(queue.FullName);
            }

            return(printersList);
        }
Exemplo n.º 33
0
        public Dictionary<string, int> GetAllPrinterQueues()
        {
            Dictionary<string, int> TempDict = new Dictionary<string, int>();

            PrintServer myPrintServer = new PrintServer(); // Get all the printers installed on this PC

            // List the print server"s queues
            PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
            foreach (PrintQueue pq in myPrintQueues)
            {
                Application.DoEvents();
                pq.Refresh();
                if (pq.Name != null)
                {
                    int PGcount = 0;
                    try
                    {
                        if (pq.NumberOfJobs > 0)
                        {
                            // We know there are jobs.  So we *have* to be able to get the collection at some point
                            DateTime Bailout = DateTime.Now.AddSeconds(5); // Keep trying for 10 seconds or until I get a valid response
                            string ErrMsg = "not yet retreived";
                            while (Bailout > DateTime.Now && ErrMsg != string.Empty)
                            {
                                try
                                {
                                    PrintJobInfoCollection Jobs = pq.GetPrintJobInfoCollection();
                                    Application.DoEvents();
                                    foreach (PrintSystemJobInfo Job in Jobs)
                                    {
                                        PGcount += Job.NumberOfPages;
                                        ErrMsg = string.Empty;
                                    }
                                }
                                catch (Exception k)
                                {
                                    ErrMsg = k.Message;
                                    MessageBox.Show(pq.Name, ErrMsg);
                                }
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Exception dork");
                    }
                    TempDict.Add(pq.Name, PGcount);
                }
            }
            return TempDict;
        }
Exemplo n.º 34
0
        /// <summary>
        /// Initialize the print helper
        /// </summary>
        public PrintHelper()
        {
            PrinterSettings settings = new PrinterSettings();
            foreach (PaperSize ps in settings.PaperSizes)
            {
                paperSizes.Add(ps);
            }

            using (PrintServer printServer = new PrintServer())
            {
                Printers = printServer.GetPrintQueues().ToDictionary(p => p,
                    p => new PrinterSettings() { PrinterName = p.FullName });
            }
        }
Exemplo n.º 35
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var server = new PrintServer();
              var queues = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,
             EnumeratedPrintQueueTypes.Connections});

              foreach (var queue in queues)
              {
            Console.WriteLine(queue.Name);
            var capabilities = queue.GetPrintCapabilities();
            foreach (PageMediaSize size in capabilities.PageMediaSizeCapability)
            { Console.WriteLine(size.ToString()); }
            Console.WriteLine();
              }
        }
Exemplo n.º 36
0
 public PrintQueueCollection GetPrinters()
 {
     try
     {
         if (!_cacheHelper.Contains("Printers"))
         {
             var printServer = new PrintServer();
             _cacheHelper.Add("Printers", printServer.GetPrintQueues(new[] {EnumeratedPrintQueueTypes.Connections,EnumeratedPrintQueueTypes.Local}));
         }
         var printers = (PrintQueueCollection)_cacheHelper.GetData("Printers");
         return printers;
     }
     catch (Exception ex)
     {
         ////TempFileLogger.LogException(ex);
         throw;
     }
 }
Exemplo n.º 37
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if ( !IsPostBack )
        {
            new Thread( new ThreadStart( metrics ) ).Start();

            string client = System.Net.Dns.GetHostEntry( Request.ServerVariables["remote_addr"] ).HostName;
            litUser.Text = client;
            hlOEM.NavigateUrl = @"\\" + client + @"\C$\Windows\OEM";
            hlBIOS.NavigateUrl = @"\\dr3docs1\Windows8\BIOS-Update";
            hlFirmware.NavigateUrl = @"\\dr3docs1\Windows8\BIOS-Update\2-BIOS-Settings-OP7010-Basic.exe";
            hlSoftware.NavigateUrl = @"\\iwmdocs\iwm\CIWMB-INFOTECH\Software2";
            hlLync.NavigateUrl = @"\\iwmdocs\iwm\CIWMB-INFOTECH\HelpCenter\RKOEN\Website\OfficeShortcuts\Lync 2013.lnk";
            hlWord.NavigateUrl = @"\\iwmdocs\iwm\CIWMB-INFOTECH\HelpCenter\RKOEN\Website\OfficeShortcuts\Word 2013.lnk";
            hlOutlook.NavigateUrl = @"\\iwmdocs\iwm\CIWMB-INFOTECH\HelpCenter\RKOEN\Website\OfficeShortcuts\Outlook 2013.lnk";
        }

        server = new PrintServer( @"\\DR3PRINT" );
        printersCollection = server.GetPrintQueues();

        foreach ( PrintQueue printer in printersCollection )
        {
            if ( printer.Name.Contains( "HP" ) || printer.Name.Contains( "NPI9EA6A6" ) || printer.Name.Contains( "AUDITS" ) || printer.Name.Contains( "Cert" ) ||
                 printer.Name.Contains( "MICR" ) || printer.Name.Contains( "KEN-SCOTT" ) || printer.Name.Contains( "COASTAL" ) || printer.Name.Contains( "Tire" ) )
            {
                continue;
            }
            printersOnServer.Add( printer.Name );
        }

        floors = stripFloorNumbers( printersOnServer );
        ddFloor.DataSource = floors;

        if ( !IsPostBack )
        {
            ddFloor.DataBind();
            ddFloor_SelectedIndexChanged( ddFloor, null );
        }
    }
Exemplo n.º 38
0
        private PrintQueue GetPrintQueue()
        {
            if (_configuration == null)
            {
                return null;
            }

            // Connect to the print server
            PrintServer printServer = null;
            try
            {
                printServer = new PrintServer(_configuration.PrintServer);
            }
            catch (PrintServerException ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, "Invalid print server name! Make sure that the print server under '{0}' is running or correct the print server name (leave blank to use local computer's print server).", ex.ServerName);
                return null;
            }

            // Pick the desired printer (even if none is selected, for convenience)
            var enpqt = new[] { EnumeratedPrintQueueTypes.Connections, EnumeratedPrintQueueTypes.Local };
            PrintQueue queue = printServer.GetPrintQueues(enpqt).FirstOrDefault(pq => pq.FullName.Equals(_configuration.PrinterName));

            // If there was a printer found, return that one
            if (queue != null)
            {
                return queue;
            }

            // Otherwise see if we are supposed to return a custom named printer ...
            if (!string.IsNullOrWhiteSpace(_configuration.PrinterName))
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Did not find a printer with name '{0}'. Using the default, local printer.", _configuration.PrinterName);
            }

            // Return the default, local printer (there is no default print queue for a print server other than the local server!).
            return LocalPrintServer.GetDefaultPrintQueue();
        }
Exemplo n.º 39
0
        static void Test1()
        {
            var page = new FixedPage();

              var server = new PrintServer();
              var queue = server
            .GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections })
            //.Single(q => q.Name == "TOSHIBA e-STUDIO4520CSeriesPCL6");
            .Single(q => q.Name == "novaPDF");
              var writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(queue);
              queue.CurrentJobSettings.Description = DateTime.Now.ToString();

              var ticket = new PrintTicket()
              {
            PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4)
            //PageOrientation = PageOrientation.ReverseLandscape
              };

              writer.Write(new MyPaginator(), ticket);
        }
Exemplo n.º 40
0
    protected void LevelsBtn_Click(object sender, EventArgs e)
    {
        rblPrinters.Items.Clear();
        PrintServer server = new PrintServer( @"\\DR3PRINT" );
        foreach ( PrintQueue printer in server.GetPrintQueues() )
        {
            // if sharp use different webpage
            if ( printer.Comment.Contains( "SHARP MX-4141N" ) )
            {
                rblPrinters.Items.Add( new ListItem( printer.Name, "http://" + printer.Name + "/device_status.html" ) );
            }
            else if ( printer.Name.Contains( "HP" ) || printer.Name.Contains( "NPI9EA6A6" ) || printer.Name.Contains( "PLOTTER" ) || printer.Name.Contains( "AUDITS" ) ||
                      printer.Name.Contains( "MICR" ) || printer.Name.Contains( "KEN-SCOTT" ) || printer.Name.Contains( "COASTAL" ) )
            {
                continue;
            }
            else if ( printer.Name.Equals( "24-COLOR-01", StringComparison.OrdinalIgnoreCase ) ||
                      printer.Name.Equals( "17K-COLOR-03", StringComparison.OrdinalIgnoreCase ) )
            {
                ListItem invalid = new ListItem( printer.Name, "https://" + printer.Name );
                invalid.Enabled = false;
                invalid.Attributes.Add( "style", "color:#999" );
                rblPrinters.Items.Add( invalid );
            }
            else
            {
                rblPrinters.Items.Add( new ListItem( printer.Name, "https://" + printer.Name ) );
            }
        }

        mpePrinters.Show();
        mpeLevels.Hide();
    }
Exemplo n.º 41
0
    protected void PollBtn_Click(object sender, EventArgs e)
    {
        List<String> problems = new List<String>();
        PrintServer server = new PrintServer( @"\\DR3PRINT" );
        PrinterObj printerobj;
        foreach ( PrintQueue printer in server.GetPrintQueues() )
        {
            try
            {
                if ( printer.Name.Contains( "HP" ) || printer.Name.Contains( "NPI9EA6A6" ) || printer.Name.ToUpper().Contains( "PLOTTER" ) || printer.Name.Contains( "AUDITS" ) ||
                     printer.Name.Contains( "MICR" ) || printer.Name.Contains( "KEN-SCOTT" ) || printer.Name.Contains( "COASTAL" ) ||
                     printer.Name.Contains( "19-BW-MFP-01" ) || printer.Name.Contains( "17K-COLOR-03" ) )
                {
                    continue;
                }
                // For Debugging
                //if ( printer.Name.Equals( "17K-ColorMFP-04", StringComparison.OrdinalIgnoreCase ) )
                //{
                //    ;
                //}
                printerobj = new PrinterObj( printer.Name );
                if ( printerobj.Low )
                {
                    printerobj.sendLowReport();
                }
            }
            catch ( Exception ex )
            {
                problems.Add( printer.Name );
                report( DateTime.Now.ToString() + printer.Name + " was not polled report. \n" + ex.ToString() );
            }
        }

        if ( problems.Count > 0 )
        {
            report( "" );
            report( "================================" );
            report( "Problem checking printers: " + DateTime.Now.ToString() );
            foreach ( String printer in problems )
            {
                report( printer );
            }
        }

        report( "END REPORT - " + DateTime.Now.ToString() );
    }