I want to create a batch file to add the current directory to my System variable PATH
, (not my User variable).
When I use:
SETX /M PATH "%CD%;%PATH%"
it does the needed thing. However, I get an error message:
data being saved is truncated to 1024 characters.
When I check the System variable using the GUI, I saw that User Path is getting added to the System Path. As a result, the System Path has duplicated entries.
I tried assigning the %PATH%
variable to a temporary variable and echoing but I saw the duplications there as well.
I saw in some stack answer that the %PATH%
variable we use in the batch file is actually a concatenation of both User Path and System Path.
At the Command Prompt, I tried:
REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH"
but I don't have idea much about whether we can use it to take that PATH value and assign to another variable.
- So I need to find a way to assign ONLY the SYSTEM PATH to a temporary variable, let's say SYS_PATHS. How can I do that?
- Is there a better way to overcome this scenario?