2011-12-29 20 views
2

我无法调用与模拟(.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"/> 

回答

0

我遇到过类似的问题,Windows 2003服务器,其中托管在IIS我的服务是执行应用程序。

我发现的事情: 1.您必须对服务权限进行调整并将其配置为输出堆栈跟踪(包括.Net放置构建服务的文件夹)。 2.启动应用程序加载用户配置文件不能从服务完成。您可以创建,包装应用,你将不加载配置文件执行,并且该应用程序可以反过来执行应用程序与用户配置文件加载。包装程序必须以释放模式构建,不得调用跟踪功能。 3.在服务改变你必须 - 在IIS重新启动应用程序池斯纳普,在 - 重启现场 - 执行IISRESET。