0

I am using a PDF control suite, that creates a print queue automatically on start up, but occasionally, if the app is terminated abnormally, the queue is not removed, so on the next start up, it creates a duplicate.

I can check for the print queues to find it, using the Printers list, but I can't see how to delete a specific queue?

4

1 回答 1

2

使用 Winspool、打印机;

获取当前打印机句柄

检索当前打印机的句柄 @返回当前打印机的 API 打印机句柄 @Desc 使用 WinSpool.OpenPrinter 获取打印机句柄。调用者拥有句柄的所有权,并且一旦不再需要句柄,就必须对其调用 ClosePrinter。不这样做会造成严重的资源泄漏!

在 Uses 子句中需要 Printers 和 WinSpool。@Raises EWin32Error 如果 OpenPrinter 调用失败。

Function GetCurrentPrinterHandle: THandle;
      Const
        Defaults: TPrinterDefaults = (
          pDatatype : nil;
          pDevMode  : nil;
          DesiredAccess : PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER
    );
      Var
        Device, Driver, Port : array[0..255] of char;
        hDeviceMode: THandle;
      Begin { GetCurrentPrinterHandle }
        Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
        If not OpenPrinter(@Device, Result, @Defaults) Then
          RaiseLastWin32Error;
      End; { GetCurrentPrinterHandle }

    {: Kill all pending jobs on the current printer }
    Procedure PurgeJobsOnCurrentPrinter;
      Var
        hPrinter: THandle;
      Begin
        hPrinter:= GetCurrentPrinterHandle;
        try
          If not WinSpool.SetPrinter( hPrinter, 0, nil,
    PRINTER_CONTROL_PURGE )
          Then
            RaiseLastWin32Error;
        finally
          ClosePrinter( hPrinter );
        end;
      End; { PurgeJobsOnCurrentPrinter } 
于 2013-12-11T11:06:11.403 回答