I am using a .bat 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 SETX command and set the path of the named variable to be %CD%, i.e. the directory the installer was run from.
This works well, although the user needs to log-off/log-on which may be annoying. This log-off/log-on 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 -m command. Unfortunately, that requires that the batch file has admin privileges. Not a problem; I ran the batch file as administrator. Well, now I ran into a problem. The current directory variable, %CD% changed from the directory the installer was run from, to C:\Windows\System32.
So now onto the question. How do I set system environment variables via a batch file which utilizes %CD% without it defaulting to C:\Windows\System32. 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 -m, the only thing needed is a log-off/log-on cycle. Otherwise, everything is automated.