Пример #1
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
            {
            }
        }
Пример #2
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;
            }
        }
Пример #3
0
        private void InitializePrinterGallery()
        {
            GalleryItem defaultPrinter = null;

            try {
                LocalPrintServer               localPrintServer       = new LocalPrintServer();
                PrintQueueCollection           localPrinterCollection = localPrintServer.GetPrintQueues();
                System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator();
                while (localPrinterEnumerator.MoveNext())
                {
                    GalleryItem item = new GalleryItem();
                    item.Image = PhotoAssistant.UI.Properties.Resources.print_32x32;
                    PrintQueue queue = ((PrintQueue)localPrinterEnumerator.Current);
                    item.Caption     = queue.FullName;
                    item.Description = queue.Description;
                    item.Value       = queue;
                    this.gcPrinter.Gallery.Groups[0].Items.Add(item);
                    if (queue == localPrintServer.DefaultPrintQueue)
                    {
                        defaultPrinter = item;
                    }
                }
            } catch { }
            this.gcPrinter.Gallery.ItemCheckedChanged += new GalleryItemEventHandler(OnPrinterGalleryItemCheckedChanged);
            if (defaultPrinter != null)
            {
                defaultPrinter.Checked = true;
            }
        }
Пример #4
0
        private void initPrinter()
        {
            //if (pq_ != null)
            //    return;

            LocalPrintServer     lps             = new LocalPrintServer();
            PrintQueueCollection queueCollection = lps.GetPrintQueues();


            PrinterSettings settings = new PrinterSettings();

            if (settings == null)
            {
                return;
            }

            string defprinter = settings.PrinterName;

            foreach (PrintQueue pq in queueCollection)
            {
                if (pq.FullName == defprinter)
                {
                    _pq = pq;
                    return;
                }
            }
        }
Пример #5
0
        public Collection <PrintQueue> GetAllPrinter()
        {
            PrintQueue       printQueue1       = null;
            LocalPrintServer localPrintServer1 = new LocalPrintServer();


            // Retrieving collection of local printer on user machine
            PrintQueueCollection localPrinterCollection1 =
                localPrintServer1.GetPrintQueues();


            //printQueue = localPrintServer.DefaultPrintQueue;



            IEnumerator <PrintQueue> all        = localPrinterCollection1.GetEnumerator();
            Collection <PrintQueue>  AllPrinter = new Collection <PrintQueue>();

            while (all.MoveNext())
            {
                printQueue1 = all.Current;
                //  this.comboBox1.Items.Add(printQueue.FullName);
                AllPrinter.Add(all.Current);
            }

            return(AllPrinter);
        }
Пример #6
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);
                }
            }
        }
Пример #7
0
        private bool PaperOut_Printer(string _ptr_device)
        {
            if (string.IsNullOrEmpty(_ptr_device))
            {
                return(false);
            }
            LocalPrintServer     localPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
            PrintQueueCollection printQueues      = localPrintServer.GetPrintQueues();

            foreach (PrintQueue item in printQueues)
            {
                item.Refresh();
                if (item.Name.ToLower() == _ptr_device.ToLower())
                {
                    string a = SpotTroubleUsingQueueAttributes(item);
                    if (a != "OK")
                    {
                        return(false);
                    }
                    a = SpotTroubleUsingProperties(item);
                    if (a != "OK")
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #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);
        }
Пример #9
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);
        }
Пример #10
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
        }
Пример #11
0
        } //Fin PrinterProperties()

        /**
         * \brief Se establecen las propiedades de las impresoras gestionadas por el Servidor de impresión
         * \details La única propiedad que nos interesa establecer y mantener para poder monitorizar los trabajos de impresión es que
         * "Conserven los documentos después de su impresión" (Se conserven los ficheros de Spool)
         */
        public static void ConfigurePrinters()
        {
            PrintQueue       printQueue = null;
            LocalPrintServer localPrintServer;

            try
            {
                /// Accedemos al Servidor de Impresión Local
                localPrintServer = new LocalPrintServer();
                Log.Debug(">>> Servidor de impresion: '" + localPrintServer.Name + "'");

                /// Accedemos a las impresoras gestionadas por el Servidor de Impresión Local
                PrintQueueCollection           localPrinterCollection = localPrintServer.GetPrintQueues();
                System.Collections.IEnumerator localPrinterEnumerator =
                    localPrinterCollection.GetEnumerator();

                /// Recorremos todas las impresoras y revisamos su configuración para que se conserven los ficheros de Spool
                while (localPrinterEnumerator.MoveNext())
                {
                    printQueue = (PrintQueue)localPrinterEnumerator.Current;
                    ApiImpresion PrintServer = new ApiImpresion();
                    PrintServer.KeepSpoolFiles(printQueue.Name);
                    printQueue.Refresh();
                } //while
            }
            catch (Exception e)
            {
                Log.Error(e);
            } //try
        }     //ConfigurePrinters()
Пример #12
0
        private IEnumerable <CloudPrinter> DoGetPrintQueues()
        {
            LocalPrintServer                PrintServer          = new LocalPrintServer();
            PrintQueueCollection            PrintQueueCollection = PrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
            Dictionary <string, PrintQueue> queuesToDispose      = new Dictionary <string, PrintQueue>(PrintQueues);

            foreach (string printername in PrinterSettings.InstalledPrinters)
            {
                if (PrintQueues.ContainsKey(printername))
                {
                    queuesToDispose.Remove(printername);
                }
                else
                {
                    var printQueue = PrintQueueCollection.SingleOrDefault(t => t.FullName == printername);
                    PrintQueues.Add(printername, printQueue);
                }
            }

            foreach (KeyValuePair <string, PrintQueue> pq_kvp in queuesToDispose)
            {
                PrintQueues.Remove(pq_kvp.Key);
                pq_kvp.Value.Dispose();
            }

            //return PrintQueues.Values.Where(q => q.is).Select(q => new CloudPrinterImpl(q)).ToArray();
            return(PrintQueues.Values.Select(q => new CloudPrinterImpl(q)).ToArray());
        }
        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);
        }
Пример #14
0
        public AddPrinterDialog(ItemCollection printersToIgnore)
        {
            InitializeComponent();
            LocalPrintServer     pServer = new LocalPrintServer();
            PrintQueueCollection printerQueueCollection = pServer.GetPrintQueues();

            // First, remove ignore printers from the printer list.
            SortedDictionary <string, PrintQueue> printers = new SortedDictionary <string, PrintQueue>();

            foreach (PrintQueue q in printerQueueCollection)
            {
                printers[q.Name] = q;
            }
            foreach (ListBoxPrinter p in printersToIgnore)
            {
                printers.Remove(p.Content as string);
            }

            // Now printers contains only printers that aren't on the ignore list. So let's add them to the UI.
            foreach (PrintQueue q in printers.Values)
            {
                PrinterListBox.Items.Add(new ListBoxPrinter(q.Name, q));
            }

            // Default to the first printer.
            PrinterListBox.SelectedIndex = 0;
        }
        public void PopulateprinterList()
        {
            PrintersList.Clear();
            var MyList = new List <string>();

            try
            {
                LocalPrintServer     myServer          = new LocalPrintServer();
                PrintQueueCollection myQueueCollection = myServer.GetPrintQueues();
                foreach (PrintQueue pQ in myQueueCollection)
                {
                    MyList.Add(pQ.Name.ToString());
                }
                var MyPrinters = MyList.ToArray();
                var items      = PrintersList.Items;
                int i          = 0;
                foreach (var value in MyPrinters)
                {
                    items.Add(value);
                    PrintersList.Items[i].ImageIndex = 0;
                    i++;
                }
            }
            catch (Exception) { }
        }
Пример #16
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);
            }
        }
Пример #17
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)
            {
            }
        }
Пример #18
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();
                }
            }
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static PrintQueue GetPrintQueue(string name, string host)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            try
            {
                dynamic    printServer;
                PrintQueue printQueue = null;
                if (String.IsNullOrWhiteSpace(host) || host == Environment.MachineName)
                {
                    printServer = new LocalPrintServer();
                }
                else
                {
                    printServer = new PrintServer(host);
                }

                if (printServer == null)
                {
                    return(null);
                }



                //name = name.Replace(host, "");

                LogHelper.LogDebug("SSSS");
                printServer.Refresh();
                LogHelper.LogDebug("Refresh");
                PrintQueueCollection printerCollection = printServer.GetPrintQueues();
                if (printerCollection == null)
                {
                    return(null);
                }

                LogHelper.LogDebug("Queues " + printerCollection.Count());
                foreach (PrintQueue printer in printerCollection)
                {
                    printer.Refresh();
                    LogHelper.LogDebug("Name " + printer.Name);
                    if (printer.Name == name)
                    {
                        LogHelper.LogDebug("Has queue");
                        printQueue = printer;
                    }
                }

                LogHelper.LogDebug("Out ");
                return(printQueue);
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
                return(null);
            }
        }
Пример #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;
            }
        }
Пример #21
0
        public static int SendCommandToPrinter(string command, string printer, string jobId = "", string documentName = "")
        {
            Dictionary <string, object>         properties = new Dictionary <string, object>();
            List <Dictionary <string, object> > printers   = new List <Dictionary <string, object> >();

            EnumeratedPrintQueueTypes[] enumerationFlags = { EnumeratedPrintQueueTypes.Local,
                                                             EnumeratedPrintQueueTypes.Shared };

            LocalPrintServer printServer = new LocalPrintServer();

            //Use the enumerationFlags to filter out unwanted print queues
            PrintQueueCollection printQueuesOnLocalServer = printServer.GetPrintQueues(enumerationFlags);
            int counter = 0;

            foreach (PrintQueue printeQueue in printQueuesOnLocalServer)
            {
                properties = new Dictionary <string, object>();

                printeQueue.Refresh();
                PrintJobInfoCollection jobsQueued = printeQueue.GetPrintJobInfoCollection();
                if (printeQueue.Name.ToLower().Trim() == printer.ToLower().Trim())
                {
                    foreach (PrintSystemJobInfo job in jobsQueued)
                    {
                        if (((job.Name.ToLower().Trim() == documentName.ToLower().Trim() && !string.IsNullOrEmpty(documentName.ToLower().Trim()))
                             ||
                             job.JobIdentifier.ToString().ToLower().Trim() == jobId.ToLower().Trim())
                            ||
                            jobId.ToLower().Trim() == "*"
                            )
                        {
                            if (command.ToLower().Trim() == "purge")
                            {
                                job.Cancel();
                                counter++;
                            }
                            else if (command.ToLower().Trim() == "pause")
                            {
                                job.Pause();
                                counter++;
                            }
                            else if (command.ToLower().Trim() == "resume")
                            {
                                job.Resume();
                                counter++;
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                }
            }

            return(counter);
        }
Пример #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);
        }
Пример #23
0
        private PrintQueueCollection listSharedPrinters()
        {
            PrintServer          printServer = new PrintServer();
            PrintQueueCollection printQueues = printServer.GetPrintQueues(new[]
            {
                EnumeratedPrintQueueTypes.Local,
                EnumeratedPrintQueueTypes.Connections
            });

            return(printQueues);
        }
 private int GetNoOfJobsQueued(string pName)
 {
     try
     {
         LocalPrintServer     myServer          = new LocalPrintServer();
         PrintQueueCollection myQueueCollection = myServer.GetPrintQueues();
         PrintQueue           pQ = new PrintQueue(myServer, pName);
         return(pQ.NumberOfJobs);
     }
     catch (Exception) { return(0); }
 }
 private string GetPrinterStatus(string pName)
 {
     try
     {
         LocalPrintServer     myServer          = new LocalPrintServer();
         PrintQueueCollection myQueueCollection = myServer.GetPrintQueues();
         PrintQueue           pQ = new PrintQueue(myServer, pName);
         return(pQ.QueueStatus.ToString());
     }
     catch (Exception) { return(" "); }
 }
Пример #26
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
        }
Пример #27
0
        public List <string> GetPrintList()
        {
            List <string>        lt          = new List <string>();
            LocalPrintServer     printServer = new LocalPrintServer();
            PrintQueueCollection printQueuesOnLocalServer = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local });

            foreach (PrintQueue printer in printQueuesOnLocalServer)
            {
                lt.Add(printer.Name);
            }
            return(lt);
        }
Пример #28
0
        private PrintTicket GetPrintTicketFromPrinter(Report_Template printerSettings)
        {
            PrintQueue printQueue = null;

            LocalPrintServer localPrintServer = new LocalPrintServer();

            // Retrieving collection of local printer on user machine
            PrintQueueCollection localPrinterCollection =
                localPrintServer.GetPrintQueues();

            System.Collections.IEnumerator localPrinterEnumerator =
                localPrinterCollection.GetEnumerator();

            if (localPrinterEnumerator.MoveNext())
            {
                // Get PrintQueue from first available printer
                printQueue = (PrintQueue)localPrinterEnumerator.Current;
                MessageBox.Show(printQueue.Name);
            }
            else
            {
                // No printer exist, return null PrintTicket
                return(null);
            }

            // Get default PrintTicket from printer
            PrintTicket printTicket = printQueue.DefaultPrintTicket;

            PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities();

            // Modify PrintTicket
            if (printCapabilites.CollationCapability.Contains(Collation.Collated))
            {
                printTicket.Collation = Collation.Collated;
            }

            if (printCapabilites.DuplexingCapability.Contains(
                    Duplexing.TwoSidedLongEdge))
            {
                printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
            }

            if (printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft))
            {
                printTicket.Stapling = Stapling.StapleDualLeft;
            }
            printTicket.PageMediaSize   = new PageMediaSize(PageMediaSizeName.JISB4);
            printTicket.PageOrientation = PageOrientation.Unknown;
            printTicket.Duplexing       = Duplexing.TwoSidedShortEdge;
            printTicket.PageResolution  = new PageResolution(PageQualitativeResolution.Draft);
            return(printTicket);
        }// end:GetPrintTicketFromPrinter()
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="printername"></param>
        /// <returns></returns>
        public static bool PrinterIsValid(string printername)
        {
            if (printername == null || printername == string.Empty || printername == "")
            {
                return(false);
            }

            LocalPrintServer     printServer = new LocalPrintServer();
            PrintQueueCollection printQueuesOnLocalServer = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
            List <string>        printers = printQueuesOnLocalServer.Select(p => p.Name).ToList();

            return(printers.Contains(printername));
        }
Пример #30
0
        private void GetPrintTicketFromPrinter()
        {
            PrintQueue printQueue = null;

            LocalPrintServer localPrintServer = new LocalPrintServer();

            // Retrieving collection of local printer on user machine
            PrintQueueCollection localPrinterCollection =
                localPrintServer.GetPrintQueues();

            System.Collections.IEnumerator localPrinterEnumerator =
                localPrinterCollection.GetEnumerator();

            while (localPrinterEnumerator.MoveNext())
            {
                // Get PrintQueue from first available printer
                printQueue = (PrintQueue)localPrinterEnumerator.Current;
            }
            //else
            //{
            //    // No printer exist, return null PrintTicket
            //    return ;
            //}

            return;

            // Get default PrintTicket from printer
            //PrintTicket printTicket = printQueue.DefaultPrintTicket;

            //PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities();

            //// Modify PrintTicket
            //if (printCapabilites.CollationCapability.Contains(Collation.Collated))
            //{
            //    printTicket.Collation = Collation.Collated;
            //}

            //if (printCapabilites.DuplexingCapability.Contains(
            //        Duplexing.TwoSidedLongEdge))
            //{
            //    printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
            //}

            //if (printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft))
            //{
            //    printTicket.Stapling = Stapling.StapleDualLeft;
            //}

            //return printTicket;
        }// end:GetPrintTicketFromPrinter()
Пример #31
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 );
        }
    }