title: Process.Start() and PATH environment variable
body: <p>I have the following trivial C# application that simply attempts to launch "jconsole.exe", which on my machine is located in C:\Programs\jdk16\bin.</p>
  
  <pre><code>using System;
  using System.Diagnostics;
  
  namespace dnet {
    public class dnet {
      static void Main( string[] args ) {
        try {
          Process.Start("jconsole.exe");
          Console.WriteLine("Success!");
        } catch (Exception e) {
          Console.WriteLine("{0} Exception caught.", e);
        }
      }
    }
  }
  </code></pre>
  
  <p>If my PATH environment variable is set to</p>
  
  <pre><code>c:\windows;c:\windows\sytem32;c:\programs\jdk16\bin
  </code></pre>
  
  <p>it works perfectly. However, if the PATH environment variable is set to</p>
  
  <pre><code>c:\windows;c:\windows\sytem32;c:\\programs\jdk16\bin
  </code></pre>
  
  <p>(note the two backslashes between "c:" and "programs"), it fails with a win32 exception.</p>
  
  <pre><code>System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
  at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
  at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
  at dnet.dnet.Main(String[] args)
  </code></pre>
  
  <p>Interestingly, in the same command prompt where I run the .NET program and get the exception, I can simply type "jconsole.exe", and the program will start. Windows appears to have no trouble finding the executable with the double backslash in the PATH, but Process.Start() does.</p>
  
  <p>Why is the extra backslash in the PATH causing problems, and how I can get around the problem? I don't know where the executable I want to call will be located at runtime, so I'd rather rely on the PATH variable.</p>