public static void DruckerKontrolle()
        {
            while (true)
            {
                //Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                //           new Action(() =>
                //           {
                //           }));



                var printerQuery = new ManagementObjectSearcher("SELECT * from Win32_Printer");
                foreach (var printer in printerQuery.Get())
                {
                    var name = printer.GetPropertyValue("Name");

                    string DruckerName      = name.ToString();
                    var    status           = printer.GetPropertyValue("Status");
                    var    isDefault        = printer.GetPropertyValue("Default");
                    string DefaultDrucker   = isDefault.ToString();
                    var    isNetworkPrinter = printer.GetPropertyValue("Network");



                    if (DefaultDrucker == "True")
                    {
                        GlobalVar.PrinterName = DruckerName;
                    }
                }


                string wmiQuery = "SELECT * FROM Win32_PrintJob";
                ManagementObjectSearcher   jobsSearcher  = new ManagementObjectSearcher(wmiQuery);
                ManagementObjectCollection jobCollection = jobsSearcher.Get();
                foreach (ManagementObject mo in jobCollection)
                {
                    if ((Convert.ToUInt32(mo["TotalPages"]) > 0) && (GlobalVar.CheckDruckActive == false))
                    {
                        foreach (var job in LocalPrintServer.GetDefaultPrintQueue().GetPrintJobInfoCollection())
                        {
                            using (PrintServer ps = new PrintServer())
                            {
                                using (PrintQueue Warteschlange = new PrintQueue(ps, GlobalVar.PrinterName, PrintSystemDesiredAccess.AdministratePrinter))
                                {
                                    Warteschlange.Pause();
                                }
                            }
                        }

                        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            WarnFenster Warnung = new WarnFenster();
                            Warnung.Show();
                        }));

                        GlobalVar.CheckDruckActive = true;
                    }
                }
            }
        }
示例#2
0
 private void cmdPauseQueue_Click(object sender, RoutedEventArgs e)
 {
     if (lstQueues.SelectedValue != null)
     {
         PrintQueue queue = printServer.GetPrintQueue(lstQueues.SelectedValue.ToString());
         queue.Pause();
     }
 }
示例#3
0
        /// <summary>
        /// Questa implementazione che è quella più intelligente, non mi funziona.
        /// Mi solleva una eccezione che dice che non sono autorizzato, non ho i permessi ????
        /// Nonostante io richieda i permessi di amministrare il server di stampa
        /// </summary>
        /// <param name="azione"></param>
        private void azioneSuSingolaStampante__NON__VA__access_denied(PrnAzione azione, String nomeStampante)
        {
            var         match       = Regex.Match(nomeStampante, @"(?<machine>\\\\.*?)\\(?<queue>.*)");
            PrintServer printServer = null;

            if (match.Success)
            {
                // Come print-server uso il server di rete
                printServer = new PrintServer(match.Groups ["machine"].Value, PrintSystemDesiredAccess.AdministrateServer);
            }
            else
            {
                // Come print-server uso me stesso
                printServer = new PrintServer(PrintSystemDesiredAccess.AdministrateServer);
            }

            using ( printServer ) {
                PrintQueue printQueue = null;
                if (match.Success)
                {
                    printQueue = printServer.GetPrintQueue(match.Groups ["queue"].Value);
                }
                else
                {
                    printQueue = printServer.GetPrintQueue(nomeStampante);
                }

                // Ricavo la coda di stampa (cioè la stampante) e le sue capacità.
                using ( printQueue ) {
                    if (azione == PrnAzione.Pause)
                    {
                        printQueue.Pause();
                    }

                    if (azione == PrnAzione.Resume)
                    {
                        printQueue.Resume();
                    }
                }
            }
        }
        private void PerformAction(ActionType action)
        {
            if (cbQueue.SelectedItem == null)
            {
                MessageBox.Show("Please select a queue");
            }

            var printerName = cbQueue.SelectedItem.ToString();

            var printers = printerName.StartsWith(@"\\") ? _printServer : _printers;

            switch (action)
            {
            case ActionType.DeleteAll:
                foreach (var jobs in printers.GetPrintQueue(printerName).GetPrintJobInfoCollection())
                {
                    jobs.Cancel();
                }
                break;

            case ActionType.Pause:
                using (PrintQueue pq = new PrintQueue(printers, printerName,
                                                      PrintSystemDesiredAccess.AdministratePrinter))
                {
                    pq.Pause();
                }
                break;

            case ActionType.Resume:
                using (PrintQueue pq = new PrintQueue(printers, printerName,
                                                      PrintSystemDesiredAccess.AdministratePrinter))
                {
                    pq.Resume();
                }
                break;
            }

            PrinterStateChanged();
        }