Printing from a Windows Service

随声附和 提交于 2019-12-02 06:24:30

问题


Ok, I am trying to print a page from a windows service that I installed using a Visual Studio setup project.

At first I set the Account property yo Local System, but it will tell me that there are no printers installed (and there are). So I changed it to user and now it just doesn't print (no error or anything).

I did some Googleing and basically it said that "Interact with Desktop" should be enabled. To programatically do this you need to edit the registry settings for this service (which really is second prize). I tried to manually set it on the properties dialog under Services, but then I need to change the Account back to Local System, which brings me back to the "No Printers Installed" problem.

Any ideas?


回答1:


I wouldn't recommend using interact with desktop. You will run into compatibility problems on Vista, Windows 7, and later versions of Windows.

You could use WTSQueryUserToken to get a user token for a logged on user and then print from that user's token. You could do this using CreateProcessAsUser to do the actual printing.

To get the logged on sessions you could use WTSGetActiveConsoleSessionId or WTSEnumerateSessions.



来源:https://stackoverflow.com/questions/2850122/printing-from-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!