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