我有一个使用mshtml.dll的Windows应用程序。它在我的Windows窗体应用程序中工作正常。
当我在Windows服务应用程序中使用相同的代码时,它会失败。我的服务以管理员身份运行。
下面是我使用的代码:
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;
}
命令是:PRINTHTML.EXE url="http://www.google.com" printername="Brother HL-2270DW series" title="" header="" footer=""
在事件日志下我发现:
Faulting module path: C:\Windows\SYSTEM32\mshtml.dll
那么,如何才能在winForm应用程序下运行相同的DLL并且在Windows服务下无效。
BTW,在Windows 7上运行正常。
所以问题是Windows 10 + mshtml.dll + Windows服务