DeletePrinter()

DeletePrinter()

Postby Davide » Sat Oct 21, 2006 2:53 pm

Hello all.

I'm trying to automatically delete a printer by the source below, but I always receive Error 5 and I don't find where's the error.
Do you see something wrong ?

Thanks,
Davide.

Code: Select all  Expand view
#include "FiveWin.ch"
#include "Struct.ch"
// #include "WinSpool.h"
#define PRINTER_ACCESS_ADMINISTER   0x00000004

function DelPrn( cName )

Local Result:=.f.,oPrnDefaults,hDC

DEFAULT cName := "Test"

  STRUCT oPrnDefaults
     MEMBER pDatatype           AS LPSTR
     MEMBER pDevMode            AS LPSTR  // LPDEVMODE
     MEMBER DesiredAccess       AS DWORD  // ACCESS_MASK
  ENDSTRUCT

  oPrnDefaults:DesiredAccess    = PRINTER_ACCESS_ADMINISTER

  IF ( ASCAN(aDevName(),{|x| Upper(x) == Upper(cName)}) >0 )   

    If OpenPrinter(cName , @hDC , oPrnDefaults:cBuffer )
      If hDC # 0
        Result := DelPrinter( hDC )
        If !Result ; MsgAlert( 'DelPrn Error ' + Str( GetLastError() ) ) ; Endif
        //
        // --- Always receive Error 5 here !!! ---
        //
        ClosePrinter( hDC )
      Endif
    Endif

  Endif

Return Result

//------------------------------------------------------------------------//

DLL32 FUNCTION ClosePrinter( pPrinter AS LONG ) AS BOOL PASCAL ;
                             FROM "ClosePrinterA" LIB "winspool.drv"

//------------------------------------------------------------------------//

DLL32 FUNCTION DelPrinter( pPrinter AS LONG ) AS BOOL PASCAL ;
                             FROM "DeletePrinter" LIB "winspool.drv"

//------------------------------------------------------------------------//

DLL32 FUNCTION OpenPrinter( pName AS LPSTR, @pPrinter AS LONG, pDef AS LPSTR ) ;
                             AS BOOL PASCAL ;
                             FROM "OpenPrinterA" LIB "winspool.drv"

//------------------------------------------------------------------------//
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Postby Antonio Linares » Sat Oct 21, 2006 6:06 pm

Davide,

#define EACCES 5 /* Permission denied */

Do you have enough privileges to delete it ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Davide » Sat Oct 21, 2006 11:59 pm

Antonio,

thank you for your reply.

Antonio Linares wrote:Do you have enough privileges to delete it ?


Yes, I can delete it either by the GUI dialog or by RUNDLL32 PRINTUI.DLL,PrintUIEntry .... (which would not work on Win9x - that's why I'm trying to do it with the APIs, even on XP)

Perhaps the problem may be in the data type of DesiredAccess ? (I already tried to pass NIL instead of the PrinterDefaults structure in OpenPrinter(), with the same results, so I though that probably I have to open the printer with administrative permissions to be allowed to delete it)

Thank you
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 101 guests