title: Service hangs up at WaitForExit after calling batch file
body: <p>I have a service that sometimes calls a batch file. The batch file takes 5-10 seconds to execute:</p>
  
  <pre><code>System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process
      proc.StartInfo.FileName = fileName;
      proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
      proc.StartInfo.CreateNoWindow = true;
      proc.Start();
      proc.WaitForExit();
  </code></pre>
  
  <p>The file does exist and the code works when I run the same code in-console. However when it runs inside the service, it hangs up at <code>WaitForExit()</code>. I have to kill the batch file from the Process in order to continue. (I am certain the file exists, as I can see it in the processes list.)</p>
  
  <p>How can I fix this hang-up?</p>
  
  <h1>Update #1:</h1>
  
  <p>Kevin's code allows me to get output. One of my batch files is still hanging. </p>
  
  <blockquote>
    <p>"C:\EnterpriseDB\Postgres\8.3\bin\pg_dump.exe" -i -h localhost -p 5432 -U postgres -F p -a -D -v -f "c:\backupcasecocher\backupdateevent2008.sql" -t "\"public\".\"dateevent\"" "DbTest" </p>
  </blockquote>
  
  <p>The other batch file is:</p>
  
  <blockquote>
    <p>"C:\EnterpriseDB\Postgres\8.3\bin\vacuumdb.exe" -U postgres -d DbTest</p>
  </blockquote>
  
  <p>I have checked the path and the <code>postgresql</code> path is fine. The output directory does exist and still works outside the service. Any ideas?</p>
  
  <h1>Update #2:</h1>
  
  <p>Instead of the path of the batch file, I wrote the "C:\EnterpriseDB\Postgres\8.3\bin\pg_dump.exe" for the <code>proc.StartInfo.FileName</code> and added all parameters to <code>proc.StartInfo.Arguments</code>. The results are unchanged, but I see the <code>pg_dump.exe</code> in the process window. Again this only happens inside the service.</p>
  
  <h1>Update #3:</h1>
  
  <p>I have run the service with a user in the administrator group, to no avail. I restored <code>null</code> for the service's username and password</p>
  
  <h1>Update #4:</h1>
  
  <p>I created a simple service to write a trace in the event log and execute a batch file that contains "dir" in it. It will now hang at <code>proc.Start();</code> - I tried changing the Account from LocalSystem to <strong>User</strong> and I set the admnistrator user and password, still nothing.</p>