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?
PATHand some very good solutions.PATH. You just want to add this folder path to localPATH. This is usually not needed because ofcmd.exesearches first always in current directory for a program or script before making use of localPATHand localPATHEXT.if "%PATH:~-1%" == ";" ( set "PATH=%PATH%%CD%" ) else ( set "PATH=%PATH%;%CD%" )to append current directory path to localPATHenvironment variable not persistent stored in Windows registry and being used only by currently running command process and all applications started from within this command process.