我有一个应该打印HTML文本的Windows服务 操作系统是7,带有.NET 4.5.1和IE 11。
代码:
private static void PrintOnStaThread(string text)
{
using (WebBrowser webBrowser = new WebBrowser())
{
webBrowser.Navigate("about:blank");
webBrowser.Document.OpenNew(false);
while (webBrowser.DocumentText != text && webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
webBrowser.Document.Write(text);
webBrowser.Refresh();
Application.DoEvents();
}
InternetExplorer internetExplorer = (InternetExplorer)webBrowser.ActiveXInstance;
internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Win32.PRINT_WAITFORCOMPLETION);
}
}
问题:
使用Local System
帐户记录服务时,ExecWB
函数不执行任何操作,并且线程正在退出,没有任何异常。使用管理员凭据记录服务时,ExecWB
功能可以正常运行,但我不想使用此帐户。
欢迎任何评论。
答案 0 :(得分:0)
这是可能的,但您需要将服务配置为"互动"。
有关详细信息,请查看此文档http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx