I am trying to add C:\\xampp\\php to my system PATH environment variable in Windows.
I have already added it using the Environment Varia
Nod to all the comments on the @Nafscript's initial SETX answer.
SETX by default will update your user path.SETX ... /M will update your system path.%PATH% contains the system path with the user path appendedPATH - SETX will truncate your junk longer than 1024 charactersSETX %PATH%;xxx - adds the system path into the user pathSETX %PATH%;xxx /M - adds the user path into the system pathThe ss64 SETX page has some very good examples. Importantly it points to where the registry keys are for SETX vs SETX /M
User Variables:
HKCU\EnvironmentSystem Variables:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
PATHappend_user_path.cmd
@ECHO OFF
REM usage: append_user_path "path"
SET Key="HKCU\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > user_path_bak.txt
SETX PATH "%CurrPath%";%1
PATHappend_system_path.cmd. Must be run as administrator.
(It's basically the same except with a different Key and the SETX /M modifier.)
@ECHO OFF
REM usage: append_system_path "path"
SET Key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > system_path_bak.txt
SETX PATH "%CurrPath%";%1 /M
Finally there's potentially an improved version called SETENV recommended by the ss64 SETX page that splits out setting the user or system environment variables.
1. Not strictly true