简体   繁体   English

打印作为Windows服务运行的脚本/应用程序

[英]Printing form a script/application which is running as Windows service

I have a bit of a (at least for me) odd problem. 我有一个(至少对我来说)奇怪的问题。 I have created a (Java) Application which (when some conditions are meet) runs a PowerShell script that uses MS-Word to print some document. 我创建了一个(Java)应用程序,该应用程序(在满足某些条件时)运行一个使用MS-Word打印某些文档的PowerShell脚本。 I run this application through a simple batch file (java call). 我通过一个简单的批处理文件(java调用)运行此应用程序。

It works like a charm when I run the application through my batch, BUT when I (using NSSM or AlwaysUp) turn it into a windows service the and trigger the printing process it fails. 当我通过批处理运行该应用程序时,它的工作原理就像一种魅力; 但是,当我(使用NSSM或AlwaysUp)将其转换为Windows服务并触发失败的打印过程时,它却起作用。 I see in the task manager that a MS-Word process is started, and it take away lots of CPU, but it does nothing (no matter how long I wait). 我在任务管理器中看到启动了MS-Word进程,它占用了大量CPU,但是却无济于事(无论我等待了多长时间)。

Simplified code: 简化代码:

$objOffice = New-Object -comobject Excel.Application
$objDoc = $objOffice.Workbooks.Open("C:\printTest\printFile.xlsx")
$objDoc.printout()
$objDoc.Close($false)
$objOffice.quit()

I have tested this on other computers as well... Same result. 我也在其他计算机上对此进行了测试...结果相同。

Also interesting: EDIT: This part written where was my fault, and fixed it. 也很有趣:编辑:这部分内容写在哪里是我的错,并将其修复。

At this point I am not even sure that it has something to do with the powershell command, but I am getting out of ideas. 在这一点上,我什至不能确定它与powershell命令有关,但是我已经摆脱了想法。

Start-Process -FilePath 'C:\printTest\printFile.xlsx' -Verb print

Also, take a look at this page , which says 另外,请看此页面 ,其中显示

You might notice the option for “Allow service to interact with desktop”, which we mentioned earlier – by default, services are not allowed to access your desktop unless this box is checked, and this checkbox is really only there for legacy support. 您可能会注意到我们前面提到的“允许服务与桌面交互”选项–默认情况下,除非选中此复选框,否则不允许服务访问您的桌面,并且该复选框实际上仅用于旧版支持。

But just checking that box doesn't immediately give them access – you would also need to make sure that the NoInteractiveServices value in the registry is set to 0, because when it is set to 1, that checkbox is ignored and services can't interact with the desktop at all. 但是,仅选中该复选框并不会立即为他们提供访问权限-您还需要确保注册表中的NoInteractiveServices值设置为0,因为如果将其设置为1,则该复选框将被忽略并且服务无法进行交互完全没有桌面。 Note: in Windows 8, the value is set to 1, and interactive services are prohibited. 注意:在Windows 8中,该值设置为1,并且禁止交互式服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM