I'm sure someone has experienced this problem before. When I call GetPrinter all is fine. Then I change the setting how I would like them also seems to work OK. When I try to SetPrinter I get the following error "System Error. Code: 5. Access is denied" This error appears to happen locally as I get error warnings in my PC's Security Event Log.
Anyone have any clues on this. It could drive a man to drink.
Cheers
Stuart
G
"Stuart Macaulay" <stuart....@sovereign.co.nz> wrote in message
news:3f0a44d4$1...@newsgroups.borland.com...
The problem is likely to be the way you call OpenPrinter to get the printer
handle. You need to specify an access mode of PRINTER_ACCESS_ADMINISTER to be
able to use SetPrinter on the handle.
{-- GetCurrentPrinterHandle -------------------------------------------}
{: Retrieves the handle of the current printer
@Returns an API printer handle for the current printer
@Desc Uses WinSpool.OpenPrinter to get a printer handle. The caller
takes ownership of the handle and <b>must</b> call ClosePrinter on it
once the handle is no longer needed. Failing to do that creates a
serious resource leak! <P>
Requires Printers and WinSpool in the Uses clause.
@Raises EWin32Error if the OpenPrinter call fails.
}{ Created 30.9.2000 by P. Below
-----------------------------------------------------------------------}
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 }
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be