Page 1 of 1

SETX /M and PATH system variable

Posted: 14 Nov 2024 01:43
by miskox
I would like to add a path (for example c:\test) to *system* variable (not user variable). Press WIN+R and type SystemPropertiesAdvanced and press ENTER. Click on 'environemnt variables'. At the top are user settings and at the bottom systemwide settings. And instead of adding a new path to the system PATH variable I would like to use SETX command. But I get this error:

Open cmd as Administrator:

Code: Select all

C:\WINDOWS\system32>setx path %path%;c:\TEST /m
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

C:\WINDOWS\system32>
I don't have a virtual machine to test this so I don't want to corrupt the PATH variable.

Anyone has a solution?

Thanks.
Saso

Re: SETX /M and PATH system variable

Posted: 14 Nov 2024 02:22
by miskox
Found it:

see https://stackoverflow.com/questions/192 ... d-problems

Code: Select all

for /f "usebackq tokens=2,*" %A in (`reg query HKCU\Environment /v PATH`) do set my_user_path=%B
setx PATH "C:\Python27;C:\Python27\Scripts;%my_user_path%"
HCKU above for user variables. For systemwide variables this registry key should be used (source ss64: https://ss64.com/nt/setx.html):

Code: Select all

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Saso