79341767

Date: 2025-01-09 07:56:33
Score: 2
Natty:
Report link

For creating a new variable with its value I simply created a .reg file that made a new registry item on the corresponding field which took care of that, for adding a value to the pre-existing PATH field out of the many values this batch file should suffice but use at your own discretion, should read the previous content and append to it.

@echo off :: Read the current Path value for /f "tokens=2*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set "CURRENT_PATH=%%B"

:: Append multiple new paths set "CURRENT_PATH=%CURRENT_PATH%;BOOM"

:: To add a new line just do (((set "CURRENT_PATH=%CURRENT_PATH%;BOOM"))) up there, Replace BOOM with desired location and remove the 3 Parenthesis' :: Add double percentage if one is present i.e. "home" = "%%home%%"

:: Write the updated Path back to the registry reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%CURRENT_PATH%" /f

:: Confirm the update echo Path variable updated with: echo - All done now! pause

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Unregistered user (0.5):
  • User mentioned (1): @echo
  • Low reputation (1):
Posted by: CrisSorryIfImWrong