Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Apr : Access Permision Error

www.cryer.info
Managed Newsgroup Archive

Access Permision Error

Subject:Access Permision Error
Posted by:"CARLO GARCIA" (carlo..@hotmail.com)
Date:Wed, 19 Apr 2006 21:14:24 -0600

Hi,

I'm trying to change printer try calling SetPrinter function, but send me
back the error "access denied".

I set pSecurityDescriptor ti null, but the same error occurs.

How can i change Permissions ?
Or how can i set the new DeviceMode without change SecurityDescriptor ?


procedure SetPrinterPageSource2(PaperSource: Word; const Name: string);
var
    W2KSDP: function(pszPrinter: PChar): Boolean; stdcall;
    H: THandle;
    Size, Dummy: Cardinal;
    PI: PPrinterInfo2;
begin
      if not OpenPrinter(PChar(Name), H, nil) then RaiseLastOSError;
      try
        GetPrinter(H, 2, nil, 0, @Size) ;
        if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError;
        GetMem(PI, Size) ;
        try
          if not GetPrinter(H, 2, PI, Size, @Dummy) then RaiseLastOSError;

          PI^.pDevMode^.dmDefaultSource:= PaperSource;
          PI^.pDevMode^.dmFields:= PI^.pDevMode^.dmFields or
DM_DEFAULTSOURCE;
          PI^.pSecurityDescriptor:= nil;

          if not SetPrinter(H, 0, PI, PRINTER_CONTROL_SET_STATUS) then
RaiseLastOSError;
        finally
          FreeMem(PI) ;
        end;
      finally
        ClosePrinter(H) ;
      end;
end;

Thanks

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive