2011-12-29 24 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。