I have a Windows Service written in C#. It is exception When the OpenPrinter method of winspool.drv is called to open the printer in the LAN
The problem only appears on Windows 7 (x64). When I run the same service code as a desktop application on Windows 7 (x64), it works fine.
var deviceName = "\\ip\printername";
IntPtr hPrinter =new IntPtr();
var DesiredAccess = PrinterAccessRights.PRINTER_ACCESS_USE | PrinterAccessRights.READ_CONTROL;
bool bRet = SpoolerApi.OpenPrinter(DeviceName, ref hPrinter, new PRINTER_DEFAULTS(DesiredAccess));
System.ComponentModel.Win32Exception (0x80004005): Access is denied
It is probably a user problem. Try to change the user running the service ( from service control manager ), maybe just for a test you can make the service run as your user. If it works you should probably change the way the printer is configured in order to make available to the user running the service, or create a custom user to run the service with access rights to the printer.