FUNCTION ClearPrintQueue(tcPrinterName) >LOCAL lnOK, lcErrorTxt, lnHandle, lcBuffer, lcPrDef > >DECLARE Long GetLastError IN kernel32.dll >DECLARE Long FormatMessage IN kernel32.dll ; > Long dwFlags, String @lpSource, Long dwMessageId, ; > Long dwLanguageId, String @lpBuffer, Long nSize, Long Arguments > >DECLARE Long OpenPrinter IN WinSpool.Drv ; > String pPrinterName, Long@ phPrinter, String pDefault >DECLARE Long ClosePrinter IN WinSpool.Drv ; > Long hPrinter >DECLARE Long SetPrinter IN WinSpool.Drv; > Long hPrinter, Long Level, ; > Long pPrinter, Long Command > >#DEFINE PRINTER_CONTROL_PURGE 3 >#DEFINE PRINTER_ACCESS_ADMINISTER 4 > >* Open a Pinter with proper access rights >lcPrDef = REPLICATE(CHR(0),8) + CHR(PRINTER_ACCESS_ADMINISTER) + REPLICATE(CHR(0),3) >lnOK = OpenPrinter( tcPrinterName, @lnHandle, lcPrDef) >IF lnOK = 0 THEN > lcErrorTxt = ApiError() > WAIT WINDOW NOWAIT "Cannot Open Printer " + tcPrinterName + CHR(13) + lcErrorTxt > RETURN -1 >ENDIF >* Clear Print Queueu >lnOK = SetPrinter( lnHandle, 0, 0, PRINTER_CONTROL_PURGE) >IF lnOK = 0 THEN > lcErrorTxt = ApiError() > = ClosePrinter( lnHandle ) > WAIT WINDOW NOWAIT "Error Clearing Print Queue" + CHR(13) + lcErrorTxt > RETURN -2 >ENDIF >= ClosePrinter( lnHandle ) >* lnOk > 0 - success >RETURN lnOk >*------------------------------------------------- > >FUNCTION ApiError >Local lcErrBuffer, lcErrorMess, liNewErr, lnErrorCode >lcErrBuffer = REPL(CHR(0),1000) >lnErrorCode = GetLastError() >liNewErr = FormatMessage(0x1000,.NULL., lnErrorCode, 0, @lcErrBuffer,500,0) >lcErrorMess = Transform(lnErrorCode) + " " + LEFT(lcErrBuffer, AT(CHR(0),lcErrBuffer)- 1 ) >RETURN lcErrorMess >Tested under WinXP only.