Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用windows服务的InfoPath静默打印不起作用_C#_Printing_Windows Services_Console Application_Infopath - Fatal编程技术网

C# 使用windows服务的InfoPath静默打印不起作用

C# 使用windows服务的InfoPath静默打印不起作用,c#,printing,windows-services,console-application,infopath,C#,Printing,Windows Services,Console Application,Infopath,我有一个windows服务,它使用xdocument.PrintOut()函数打印InfoPath表单的默认视图。除一种情况外,它适用于多种机器配置。它在运行Windows 2012(和Win2012R2)(x64)、SharePoint 2013(x64)和Office professional plus 2013(x86)的某些计算机上不起作用。我不确定SharePoint是否与此问题有关 下面是我检查流程监视器日志上的差异时发生的情况 当作为windows服务执行并调用xdocument.

我有一个windows服务,它使用
xdocument.PrintOut()
函数打印InfoPath表单的默认视图。除一种情况外,它适用于多种机器配置。它在运行Windows 2012(和Win2012R2)(x64)、SharePoint 2013(x64)和Office professional plus 2013(x86)的某些计算机上不起作用。我不确定SharePoint是否与此问题有关

下面是我检查流程监视器日志上的差异时发生的情况

当作为windows服务执行并调用
xdocument.PrintOut()
时,它在后台启动
INFOPATH.EXE
,发送打印命令,启动spoolsv.EXE(打印机后台打印程序),打印机后台打印程序检测默认打印机,之后不会发生任何事情

当使用console应用程序执行相同的代码时,会发生一组类似的事件,此外,还会在“
C:\Windows\System32\spool\PRINTERS\FP00003.SPL
”和“
C:\Windows\System32\spool\PRINTERS\FP00003.SHD
”处创建后台打印程序文件。SPL文件是实际的假脱机(打印作业)文件。SHD文件提供有关打印作业发送到哪台打印机以及打印作业来自谁的信息

请注意,该服务使用与运行console应用程序时相同的帐户运行,并且所有系统上的打印机驱动程序始终相同。此外,运行完全相同的代码,但通过自动将MS Word从服务打印到同一打印机,也可以很好地工作

我试图解释这个问题,请随时通过评论要求澄清

以下是Windows服务和控制台应用程序中使用的代码:

//** Create inforpath application instance
Microsoft.Office.Interop.InfoPath.Application app = new Microsoft.Office.Interop.InfoPath.Application();
//** Open XML file
XDocument xdoc = app.XDocuments.Open(@"F:\InfoPathTestFiles\8f2de6cb86594203b5ecb301cb2f4a94.xml", 1);
//** give enough time for infopath.exe to open the XML file
System.Threading.Thread.Sleep(5000);
//** Send print command.
xdoc.PrintOut();
//** let it cool for 5 seconds.
System.Threading.Thread.Sleep(5000);
//** quit the application.
app.Quit(true);

请注意,需要完全信任InfoPath文件(xml)才能以这种方式打印。

从不、从不、从不从服务打印。您看不到打印机驱动程序显示的错误对话框。我们创建了一个自定义打印机,用于打印到端口,端口名指向文件。当请求发送到此打印机时,它会在指定的文件夹中创建一个文件。此外,自定义打印机设置为默认打印机。当您使用console应用程序运行.PrintOut()时,它会起作用,而使用该服务时则不起作用。我同意Hans的观点,您无法看到错误对话框,但我正在打印的文档非常简单,打印时没有错误。从不,从不,从不从服务打印。您看不到打印机驱动程序显示的错误对话框。我们创建了一个自定义打印机,用于打印到端口,端口名指向文件。当请求发送到此打印机时,它会在指定的文件夹中创建一个文件。此外,自定义打印机设置为默认打印机。当您使用console应用程序运行.PrintOut()时,它会起作用,而使用该服务时则不起作用。我同意Hans的观点,您无法看到错误对话框,但我正在打印的文档非常简单,打印时没有错误。