title: Setting environment variables for the system through a batch file
body: <p>I am using a <code>.bat</code> file to automate some tasks for my engine (once it is freshly cloned from the repository). One of the tasks is setting the environment variables. I am using the <code>SETX</code> command and set the path of the named variable to be <code>%CD%</code>, i.e. the directory the installer was run from. </p>
  
  <p>This works well, although the user needs to <code>log-off/log-on</code> which may be annoying. This <code>log-off/log-on</code> cycle is not required if the variable is set as the system variable (I am not sure why but restarting Visual Studio has no effect on user environment variables... that is, it detects no changes but it will detect changes in system variables). So I proceeded to use the <code>-m</code> command. Unfortunately, that requires that the batch file has admin privileges. Not a problem; I ran the batch file as administrator. Well, <em>now</em> I ran into a problem. The current directory variable, <code>%CD%</code> changed from the directory the installer was run from, to <code>C:\Windows\System32</code>. </p>
  
  <p>So now onto the question. <strong>How do I set system environment variables via a batch file which utilizes <code>%CD%</code> without it defaulting to <code>C:\Windows\System32</code></strong>. Just as a note, quite a few people use the installer and I would like this process to be as painless and mistakes free as possible. Which means, no manual entry is preferred. Currently, if run without admin privileges and without <code>-m</code>, the only thing needed is a <code>log-off/log-on</code> cycle. Otherwise, everything is automated. </p>