0

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

user2404597
  • 488
  • 4
  • 18
  • refer http://stackoverflow.com/questions/31853699/mshtml-dll-on-windows-10, this might answer your question – Ankit Vijay Jan 14 '16 at 03:30
  • Ankit, I tried it already...no luck. – user2404597 Jan 14 '16 at 03:31
  • What *Command* are you trying to run? Services don't run in the user desktop, so they can't interact with it. As the only thing in your code that might interact with mshtml.dll would be the call you're making to `Process.Start`, and since you've not included what `Command` you're providing, it's difficult to say. The indication it works in WinForms and not from a service tells me you're trying to interact with the active desktiop, which (again) a service app can no longer do since Windows Vista was released. – Ken White Jan 14 '16 at 04:13
  • command is : PRINTHTML.EXE url="http://www.google.com" printername="Brother HL-2270DW series" title="" header="" footer="" . please note it works with Windows 7. – user2404597 Jan 14 '16 at 04:28

0 Answers0