Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Executing batch file with ProcessStartInfo
  2. internal bool ExecuteBatchFile(string fileName, int executionTime)
  3.     {
  4.         var exitCode = -1;
  5.         var error = string.Empty;
  6.         try
  7.         {
  8.  
  9.             var hubStartInfo = new ProcessStartInfo
  10.             {
  11.                 CreateNoWindow = false,
  12.                 FileName = fileName,
  13.                 UseShellExecute = false
  14.             };
  15.  
  16.             var process = new Process { StartInfo = hubStartInfo };
  17.             process.Start();
  18.             process.WaitForExit(executionTime);
  19.  
  20.             if (process.HasExited)
  21.             {
  22.                 exitCode = process.ExitCode;
  23.                 if (exitCode == 0)
  24.                 {
  25.                     return true;
  26.                 }
  27.                 error = process.StandardError.ReadToEnd();
  28.             }
  29.             else
  30.             {
  31.                 return true;
  32.             }
  33.  
  34.             return false;
  35.         }
  36.         catch (Exception e)
  37.         {
  38.             return false;
  39.         }
  40.     }
  41.        
  42. private void simpleRun_Click(object sender, System.EventArgs e)
  43. {
  44.   System.Diagnostics.Process.Start(@"C:listfiles.bat");
  45. }