I have a Windows Application which uses mshtml.dll. It works fine within my Windows Form application.
When I use the same code within my Windows Service app then it fails. My Service runs as an Administrator.
below is the code I use:
private string PrintUsingPrinterExe(string Command)
{
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + Command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
//StreamWriter streamWriter = proc.StandardInput;
//StreamReader outputReader = proc.StandardOutput;
//StreamReader errorReader = proc.StandardError;
//while (!outputReader.EndOfStream)
//{
// string text = outputReader.ReadLine();
// streamWriter.WriteLine(text);
//}
//while (!errorReader.EndOfStream)
//{
// string text = errorReader.ReadLine();
// streamWriter.WriteLine(text);
//}
//streamWriter.Close();
proc.WaitForExit(12000);
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
if (!proc.HasExited)
{
proc.Kill();
}
// Display the command output.
return result;
}
command is : PRINTHTML.EXE url="http://www.google.com" printername="Brother HL-2270DW series" title="" header="" footer=""
Under event Log I find this:
Faulting module path: C:\Windows\SYSTEM32\mshtml.dll
So, how could it be possible that same DLL works just fine under winForm app and does not work under Windows Service.
BTW, same service runs fine on Windows 7.
so issue is Windows 10 + mshtml.dll + Windows Service