我无法调用与模拟(.NET 4.0)的批处理文件起动过程中不与模拟
我有一个调用驻留在服务器的本地文件系统上的测试批处理文件的Web应用程序的工作。当我没有模仿地运行它时,它运行良好。但是通过模拟,批处理文件不会产生任何输出,也不会返回任何错误。
下面是执行,我使用批处理文件中的代码 -
public static bool ExecuteBatchFile(string fileLocationPath, string filePath, string arguments, TextBox textBox)
{
try
{
ProcessStartInfo procStartInfo = new ProcessStartInfo(filePath);
procStartInfo.UseShellExecute = false;
procStartInfo.Arguments = arguments;
procStartInfo.WorkingDirectory = fileLocationPath;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.RedirectStandardInput = true;
procStartInfo.UserName = "XYZ";
procStartInfo.Domain = "ABC";
System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in "PWD")
pwd.AppendChar(c);
procStartInfo.Password = pwd;
procStartInfo.LoadUserProfile = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
textBox.Text += "output rcvd\r\n";
textBox.Text += e.Data;
};
proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
textBox.Text += "error rcvd\r\n";
textBox.Text += e.Data;
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
proc.Close();
return true;
}
catch (Exception e)
{
textBox.Text += e.Message;
return false;
}
}
没有冒充我可以看到该批处理文件的输出。我得到的输出与批处理文件的输出接收,然后是一个空的OutputReceived,然后是一个空的ErrorReceived。
但随着模仿,我什么都看不到!只有一个OutputReceived没有数据的事件,一个没有数据的ErrorReceived事件。
我已经在Web配置文件中设置模拟如下:
<identity impersonate="true" userName="ABC\XYZ" password="PWD"/>