SETX /M and PATH system variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 630
Joined: 28 Jun 2010 03:46

SETX /M and PATH system variable

#1 Post by miskox » 14 Nov 2024 01:43

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

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: SETX /M and PATH system variable

#2 Post by miskox » 14 Nov 2024 02:22

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

Post Reply