C# 启动进程不使用模拟

C# 启动进程不使用模拟,c#,asp.net,.net-4.0,C#,Asp.net,.net 4.0,调用带有模拟(.NET 4.0)的批处理文件时遇到问题 我有一个web应用程序,它调用驻留在服务器本地文件系统上的测试批处理文件。当我在没有模拟的情况下运行它时,它运行良好。但是通过模拟,批处理文件不会产生任何输出,也不会返回任何错误 以下是执行我使用的批处理文件的代码- public static bool ExecuteBatchFile(string fileLocationPath, string filePath, string arguments, TextBox textBox)

调用带有模拟(.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

但是通过模仿,我什么也看不见!只有一个事件表示接收到的输出没有数据,一个事件表示接收到的错误没有数据

我在web配置文件中设置了模拟,如下所示:

<identity impersonate="true" userName="ABC\XYZ" password="PWD"/>

我在Windows 2003 Server上遇到了类似的问题,我在IIS中托管的服务正在执行应用程序

我发现的事情: 1.您必须调整服务的权限,并将其配置为输出堆栈跟踪(包括.Net放置生成服务的文件夹)。 2.无法从服务启动应用程序并加载用户配置文件。您可以创建包装应用程序,您将在不加载配置文件的情况下执行该应用程序,而该应用程序可以在加载用户配置文件的情况下执行该应用程序。包装器必须在发布模式下构建,不得调用跟踪函数。 3.更换服务时,您必须 -在IIS管理单元中重新启动应用程序池 -重新启动站点
-执行iisreset。

我在Windows 2003 Server上遇到了类似的问题,我在IIS中托管的服务正在执行应用程序

我发现的事情: 1.您必须调整服务的权限,并将其配置为输出堆栈跟踪(包括.Net放置生成服务的文件夹)。 2.无法从服务启动应用程序并加载用户配置文件。您可以创建包装应用程序,您将在不加载配置文件的情况下执行该应用程序,而该应用程序可以在加载用户配置文件的情况下执行该应用程序。包装器必须在发布模式下构建,不得调用跟踪函数。 3.更换服务时,您必须 -在IIS管理单元中重新启动应用程序池 -重新启动站点 -执行iisreset