title: C#: PATH Environment Variable
body: <p>I have a problem, I've written a code to install a batch file to the registry and to the PATH under Advanced Settings, so it can be used under the right click menu.</p>
  
  <p>It works until I click on this right click item. After that it just shows a window for a millisecond (I don't know which one) and nothings happens.</p>
  
  <p>The batch file is working (I tested it). I also checked the registry entry (it is 100% correct, like it should be when I do it manually). So the only thing is left is the PATH under Advanced System Settings...</p>
  
  <p>First the code:</p>
  
  <pre><code>Environment.SetEnvironmentVariable(
      "PATH", 
      Environment.GetEnvironmentVariable("PATH") + ";" + 
          Path.GetPathRoot(Environment.SystemDirectory) + "FastAndDelete\\",
      EnvironmentVariableTarget.Machine);**
  
  RegistryKey reg = Registry
      .ClassesRoot.OpenSubKey("Directory", true)
      .OpenSubKey("shell", true);
  reg.CreateSubKey("FastAndDelete");
  reg.OpenSubKey("FastAndDelete", true)
      .CreateSubKey("command")
      .SetValue("", "cmd /c " + '“' + "cd %1 &amp;&amp; fastdel.bat" + '”');
  reg.Close();
  </code></pre>
  
  <p>I also tried</p>
  
  <pre><code>Environment.SetEnvironmentVariable(
      "PATH", 
      Environment.GetEnvironmentVariable("PATH") + ";" + 
          Path.GetPathRoot(Environment.SystemDirectory) + 
          "FastAndDelete\\;", 
      EnvironmentVariableTarget.Machine);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Environment.SetEnvironmentVariable(
      "PATH", 
      Environment.GetEnvironmentVariable("PATH") + ";" + 
          Path.GetPathRoot(Environment.SystemDirectory) + 
          "FastAndDelete\\fastdel.bat", 
      EnvironmentVariableTarget.Machine);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Environment.SetEnvironmentVariable(
      "PATH", 
      Environment.GetEnvironmentVariable("PATH") + ";" + 
          Path.GetPathRoot(Environment.SystemDirectory) + 
          "FastAndDelete\\fastdel.bat;", 
      EnvironmentVariableTarget.Machine);
  </code></pre>
  
  <p>I also tried it without the ";" at the beginning, but nothing helps.</p>
  
  <p>Do someone know what I am doing wrong?</p>