title: How to set PATH environment variable in batch file only once on Windows?
body: <p>I have batch file that sets user path and is run as part of Visual Studio IDE build step.</p>
  
  <pre><code>@ECHO OFF
  @ECHO %PATH%
  set COMSPEC = "%VCINSTALLDIR%\vcvarsall.bat" amd64
  setx PATH "..\..\lib\libsndfile;..\..\lib\simulink" 
  @ECHO %PATH%
  </code></pre>
  
  <p>When I build the project, close VS, and reopen it, and rebuild, I see
  appended path as part of <code>PATH</code> variable. However, I see that in Windows setting of environment variable <code>PATH</code> variable is created under user environment variables as</p>
  
  <pre><code>..\..\lib\libsndfile;..\..\lib\simulink
  </code></pre>
  
  <p><strong>Question 1:</strong></p>
  
  <p>Why does this path also appear as appended path as part of system environment variable?</p>
  
  <p>On executing <code>echo %PATH%</code> through Visual Studio console (when I run the project second times) prints system variable path and the new path I created appended to it.</p>
  
  <p><strong>Question 2:</strong></p>
  
  <p>I want to modify my batch file so that it only sets once <code>PATH</code> environment variable in user settings during first run of Visual Studio build. If the user variable <code>PATH</code> already exists on subsequent runs, it should not execute <strong>set</strong> command again to avoid appending new path again and again in system variable.</p>
  
  <p>Any ideas how to achieve this?</p>