2010-12-02 62 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

我的下一组是尝试设置服务作为您登录的用户运行时运行。这样你就会知道它是否是特定于网络服务帐户的东西,它正在停止工作

相关问题