PrintToPrinter在Windows服务中失败 [英] PrintToPrinter fails in Windows Service

查看:305
本文介绍了PrintToPrinter在Windows服务中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Windows服务调用PrintToPrinter,但抛出以下异常:

进程无法访问该文件,因为它正被另一个进程使用

我尝试将Windows服务用户更改为管理员(我知道这通常是一个坏主意),但这不会改变任何事情。有人知道我的问题可能是什么原因吗?

I have tried changing the windows service user to administrator (I know that is generally a bad idea), but that doesn't change anything. Anybody has an idea what might be the cause of my problem?

(对于那些想知道为什么我甚至尝试从Windows服务打印的人:我真的想生成一个pdf文件。水晶报告由于某种原因生成了非常大的pdf文件,所以我使用"虚拟打印机"Amyuni,当我打印水晶报告时会生成一个小得多的文件。这就是我注意到问题的地方。试图改为普通的打印机没有帮助。如果我在Windows应用程序甚至是Web服务上执行它,一切正常。)

(For those who wonder why I even try to print from a windows service: I am really trying to generate a pdf-file. Crystal reports generates for some reason very large pdf-files, so I use the "virtual printer" Amyuni which generates a much smaller file when I print the crystal report to it. That is where I noticed the problem. Trying to change to a normal printer did not help. Everything works fine if I do it in a windows app or even on a web service.)

推荐答案

通常是由访问打印机引起的。在本地系统帐户下运行可能没有本地用户帐户打印机的权限。搜索她以获取有关如何更新注册表的更多信息,以便服务可以访问所有打印机。我相信
它需要从用户导出和导入到本地系统注册表项。

Typically it's caused by access to the Printer. Running under a local system account may not have rights to the local user account printer. Search her for more info on how to update the registry so the Services have access to all of your printers. I believe it requires exporting and importing from the User to Local System registry keys.

也可能是你没有打开报告作为临时副本,系统是锁定RPT文件。

It may also be that you are not opening the report as a Temp copy and the system is locking the RPT file.

Don


这篇关于PrintToPrinter在Windows服务中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆