问题
I have a friend who did the same thing with window form.
What I need is to make this to a window service.
The Window service program (printing controller service) will be used as a central printer controller.
Depending on the condition, I will send the printing job to different printer on the network (the printer is installed on USB).
It is already possible to do a test print, but when I list down the installed printers, these network printers are not listed.
But in my friend's program, all he need to do is to set the printer name to the ip address of the machine, and for that machine, just make sure that it is set to the default printer.
Once my friend set the ipaddress and trigger print, it will be printed to the correct printer. But for my case, the window service already did not list down the network printers, it will not print if printer name is wrong.
For my window service, I'm using Local System.
heard about creating a local port with the relevant IP address of the printer, but have yet to manage to test.
Hope that someone is able to give some guidance
回答1:
Printing from a windows service is not recommended. Windows service runs in background and have no UI. You can look into: Print html document from Windows Service in C# without print dialog
EDIT
"For my window service, I'm using Local System."
I guess you need to use a different account for your service,( domain account) so that you can access network resources.
回答2:
Have sort of gave up on using window service, as when I log down the printers my computer can access, it will only show only those installed locally, those network printers are not recognized somehow.
Tried with standard TCP/IP port, have no problems setting up, but unable to even do a test print.
Decided to trade off by using window form, setting the default printer according to the mapping and issue a print command. Tested and it worked. This way, the user will only need to login the computer each day, but the advantage is that there will be no issue for the need of additional settings with regards to permission and access rights
来源:https://stackoverflow.com/questions/3996047/network-printing-with-window-service