简体   繁体   中英

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. I run this application through a simple batch file (java call).

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. 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).

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.

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. Note: in Windows 8, the value is set to 1, and interactive services are prohibited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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