Answered by:
No printers found in Windows 8 service

Question
-
I am trying to port a Windows service (runs as local system) that runs on previous Windows versions. However, on Windows 8 the call to the Win32 API function EnumPrinters returns 0 in the pcbNeeded argument (implying that there are no printers installed) unless there is a user already logged into the system when the service is started.
I tried making my service depend on the spooler service but that didn't help.
Is there any workaround for this behavior?
- Moved by Jesse Jiang Tuesday, April 9, 2013 7:48 AM
Monday, April 8, 2013 4:43 PM
Answers
-
I got it working by setting up a retry loop. EnumPrinters finally sees printers after about 45 seconds from the first time I call it.
I also removed the call to LoadUserProfile and set the service to run as localsystem and it still works with the retries.
Dave
- Marked as answer by Dave Burns Wednesday, April 10, 2013 2:42 PM
Wednesday, April 10, 2013 2:42 PM
All replies
-
Recall that the printers are assigned based on the user profile. However, services don't automatically load the user profile since they are not expected to communicate with mapped network drives, printers, etc.
Modify your Windows service so that it runs under a particular user account where the printer is defined. In the code itself, call LoadUserProfile(). See if this solves your problem.
Monday, April 8, 2013 5:50 PM -
Hello,
Welcome here.Based on your description, I will move this thread to a more appropriate forum: Windows Desktop SDK.
Thanks for your understanding.
Regards,Elegentin Xie
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, April 9, 2013 7:49 AM -
Thanks for moving this. However, there is no direct link to this forum from the main forums page at http://msdn.microsoft.com/subscriptions/aa974230.aspx, nor is there a link to all forums from that page.
Regards, Dave
Tuesday, April 9, 2013 10:30 AM -
Thanks for the suggestion Brian.
It doesn't work however. I changed the service to run as a specific user account and added a call to LoadUserProfile before calling EnumPrinters and got the same result.
This must be a new thing with Windows 8, because it was never a problem before on Windows 7, Vista, and XP.
Dave
Tuesday, April 9, 2013 3:50 PM -
I got it working by setting up a retry loop. EnumPrinters finally sees printers after about 45 seconds from the first time I call it.
I also removed the call to LoadUserProfile and set the service to run as localsystem and it still works with the retries.
Dave
- Marked as answer by Dave Burns Wednesday, April 10, 2013 2:42 PM
Wednesday, April 10, 2013 2:42 PM