在 WinServer 2008 中从非交互式进程(Windows 服务、计划任务等)打印 PDF
我正在尝试编写一个打印 PDF 的非交互式进程,我需要有关如何在 Windows Server 2008(和 Vista/7)上构建它的建议。
之前,我们有一个计划任务(设置为无论用户帐户是否登录都运行),该任务将打印目录中的所有 PDF。 (一个单独的进程会将 PDF 移动到目录中。)在运行时,这将启动另一个进程(Adobe Reader 或 Foxit Reader)来打印 PDF。 Adobe Reader 和 Foxit Reader 都具有静默打印功能,因此所有内容都会发送到运行计划任务的用户的默认打印机。从未生成任何用户界面,并且所有文件都将顺利打印。 这适用于 Server 2003。
该过程不再适用于 Server 2008。我不完全确定,但我相信这与会话 0 隔离有关。我无法证明这一点。但是,我可以说,当设置为“仅在用户登录时运行”时,该进程将作为计划任务运行。现在,虽然这有效,但它强制用户登录到机器,因此不能满足我的要求。 (我的第一条线索是上一个问题。
)无法确定我该如何继续前进。有什么办法可以满足我的要求吗?
一些注意事项:
我看到的每个解决方案似乎都在使用登录用户的凭据。请参阅我上面链接的问题 - 列出的解决方案似乎正在获取登录用户的令牌 -在用户中并使用它来运行程序。 (查看 GetCurrentUserToken() 过程 - 返回的值稍后将在 API 调用 CreateProcessAsUser() 中使用。)
据我所知,我当前的流程没有生成任何 UI。 我已验证,使用 ProcMon,读取器进程(Adobe 或 Foxit)似乎可以正确打印,而打印驱动程序本身似乎有问题。这是通过尝试使用打印到文件驱动程序来支持的 - 打印到文件驱动程序以三个可见步骤运行,并明确完成所有文件的第一个步骤,而无需启动第二个步骤。那么Session 0 Isolation对打印机驱动程序有何影响呢?我不清楚。 (我能找到的关于该主题的最佳文档仅提及即使打印后台处理程序在会话 0 中运行,打印机驱动程序也可能会受到影响。)
作为 Windows 服务进行打印永远无法正常工作,即使该进程已选中“允许服务与桌面交互”。
添加粗体文本是为了对抗模糊的文本墙效果。
I am trying to write a non-interactive process that prints PDFs, and I need advice on how to build this on Windows Server 2008 (and Vista/7).
Previously, we have had a scheduled task (set to run whether the user account was logged on or not) that would print all PDFs inside of a directory. (A seperate process would move the PDFs into the directory.) At runtime, this would spin up another process (either Adobe Reader or Foxit Reader) to print the PDF. Both Adobe Reader and Foxit Reader feature silent printing, so everything would be sent to the default printer for the user that the scheduled task ran as. No UI was ever generated, and all files would be printed without a hitch. This worked on Server 2003.
The process no longer works on Server 2008. I'm not entirely sure, but I believe this has to do with Session 0 Isolation. I cannot prove this. However, I can say that the process works as a scheduled task when set as "Run only when the user is logged in". Now, while this works, it forces a user to log in to the machine, and thus does not fulfill my requirements. (My first clue was in this previous question.)
I cannot determine how I can move forward on this. Is there any way to fulfill my requirements?
A few notes :
Every solution I've seen seems to be using the credentials of a logged-in user. See the question I linked above - the solution listed appears to be grabbing the token of a logged-in user and using it to run the program. (Look at the GetCurrentUserToken() procedure - the returned value is later used in the API call CreateProcessAsUser().)
My current process generates, as near as I can tell, no UI. I've verified, using ProcMon, that the reader process (Adobe or Foxit) appears to print correctly and the print driver itself appears to have a problem. This is backed up by an attempt to use a print-to-file driver - the print-to-file driver runs in three visible steps and clearly finishes the first for all files without starting the second. So how does Session 0 Isolation affect the printer driver? This is unclear to me. (The best documentation I can find on the subject only mentions that printer drivers may be affected, even though the print spooler runs in Session 0.)
Printing as a Windows service never works, even when the process has 'Allow service to interact with desktop' checked.
Bold text added to counter the blear-inducing wall-of-text effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 Foxit Reader 而不是 Acrobat-Reader。
福昕阅读器支持无 GUI/命令行正确执行,在 Windows 2008 及更高版本中也是如此!
打印也是可能的,但每次运行打印作业时,您都必须在 session0 中添加(或检查)打印机。
如果您需要更多帮助,请再次询问。我已经构建了一个 powershell 脚本,该脚本在任务调度程序中运行,以在 Foxit Reader 的帮助下打印 pdf 文件。
Try using Foxit Reader instead of Acrobat-Reader.
Foxit Reader supports GUI-less / commandline execution properly, also in Windows 2008 and above!
Printing is also possible, but you will have to add (or check) the printer in session0 every time you run the printjob.
If you need any more help on that, just ask again. I already built a powershell script which runs in task scheduler to print pdf-files with help of Foxit Reader.