static void Main(string[] args) { var allPrinters = Spooler.EnumLocalPrinters(false); foreach (var printer in allPrinters) { Console.WriteLine(printer); } using (var spooler = new Spooler()) { spooler.PauseNewJobsProc(allPrinters); } }
private void Proc(List <string> stopThesePrinters) { for (; ;) { if (StopStopping) { break; } try { Spool.PauseNewJobsProc(stopThesePrinters); // if PauseNewJobsProc returns, it's a clean shutdown break; } catch (SpoolerAccessPI.InteropHelpers.FatalNativeCodeException exc) { TheEventLog.WriteEntry(string.Format( "{0} (function {1} returned code {2})", exc.Message, exc.NativeFunction, exc.ErrorCode ), EventLogEntryType.Error); break; } catch (SpoolerAccessPI.InteropHelpers.NativeCodeException exc) { if (StopPrintJobs.Properties.Settings.Default.LogLevel > 0) { TheEventLog.WriteEntry(string.Format( "{0} (function {1} returned code {2})", exc.Message, exc.NativeFunction, exc.ErrorCode ), EventLogEntryType.Warning); } if (StopPrintJobs.Properties.Settings.Default.StopOnNonfatalError) { // don't try again break; } } } }