I have a Windows service that should print out HTML text.
The OS is 7, with .NET 4.5.1 and IE 11.
The code:
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);
}
}
The problem:
When the service is logged using the Local System account the ExecWB function does nothing and the thread is exiting without any exception. When the service is logged using the Administrator credentials the ExecWB function works perfectly, but I don't want to use this account.
Any comments will be welcome.