How to add to the path environment variable

Hello, I do apologize if this has been sorted out somewhere but I keep reading different ways to do it, but none of them work for me…

I want to add to the path a value like
set PATH=%PATH%;NEWVALUE which works fine in a command line

But it does not work when using it inside an action… using like
wait cmd /c “set PATH=%PATH%;NEWVALUE”

or just
wait set PATH=%PATH%;NEWVALUE

I won’t mind either changing the value directly in the regedit as:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControllerSet\Session Manager\Environment
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;c:\NEWVALUEHERE

but the append file or the regset are also playing up.

Any help will be appreciated.

Hi,

We had a similar issue with JAVA_HOME environmental variable. We were able to solve this issue by running the regset command.

Your action could look something like this:
regset “[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]” “PATH”=“NEWVALUEHERE”

You want ‘setx -m’ instead of just ‘set’. That will make it persistent. It will take effect upon reboot of the OS.

wait cmd /c setx -m PATH “%PATH%;NewValue”

have you tried?
dos set PATH=%PATH%;NEWVALUE

or you can do an on the registry entry like

delete __createfile
delete wizardedit.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControllerSet\Session Manager\Environment]
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;c:\NEWVALUEHERE
@end_create_reg_file

move __createfile wizardedit.reg
waithidden regedit /s "wizardedit.reg"

I don’t think that either of those will work for what he’s trying.

Using the ‘dos’ command will change the path only for that instance of the command shell - which is going to terminate immediately after running the set command, and isn’t going to be inherited by the next shell.

Couple of typos in the regedit command as well, the path is actually “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” and need to specify the value name “Path”. I think it would look like this, (untested):

delete __createfile
delete wizardedit.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
Path={values "Path" of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" of registry};c:\NEWVALUEHERE
@end_create_reg_file

move __createfile wizardedit.reg
waithidden regedit /s "wizardedit.reg"

Hello Everyone and thank you for the help.

Unfortunate none of the solutions provided is working…:-(, for some reason the Path does not get change. I check out the wizardedit.reg file and apart from having a space before the new path, everything seems in order.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NTP\BIN; C:\xxxx\b1

removed the space from the file itself and try to import the file, but even if it says it succeeds, the key does not get the new value in.

The server is 2016 but I tried with at 2012 and obtained the same results.

I resolved the problem by using good old spb file packager, but I am willing to continue to test if anyone has more ideas as I cannot understand why I cannot modify the path key.

Thanks

Oops, I forgot to disable 32-bit redirection on mine.