2010-12-02 86 views
0

我正在使用以下代碼從C#運行批處理文件。以下代碼是我的Windows服務的一部分。此代碼在Windows XP中運行得非常好,但是當我將Windows服務部署到Windows Server 2003操作系統時,它將返回退出代碼1(失敗)。有人知道我錯過了什麼嗎?我需要給予Windows服務一些特別許可嗎?該服務作爲本地系統服務安裝。無法從Windows服務器2003中的Windows服務運行批處理文件操作系統

 ProcessStartInfo psi = new ProcessStartInfo(); 

     //specify the name and arguments to pass to the command prompt 
     psi.FileName = ConfigurationManager.AppSettings["BatchFilePath"]; 
     psi.Arguments = fileName; 


     //Create new process and set the starting information 
     Process p = new Process(); 
     p.StartInfo = psi; 

     //Set this so that you can tell when the process has completed 
     p.EnableRaisingEvents = true; 

     p.Start(); 

     //wait until the process has completed 
     while (!p.HasExited) 
     { 
      System.Threading.Thread.Sleep(1000); 
     } 

     //check to see what the exit code was 
     if (p.ExitCode != 0) 
     { 
      logger.Write("Exit Code" + p.ExitCode); 
     } 
+1

什麼是成功返回批處理文件? – Oded 2010-12-02 16:49:09

+0

成功時返回0 – 2010-12-02 16:50:31

回答

1

我的下一組是嘗試設置服務作爲您登錄的用戶運行時運行。這樣你就會知道它是否是特定於網絡服務帳戶的東西,它正在停止工作

相關問題