rem local environment
reg delete "HKCUEnvironment" /f /v {ENVIRONMENT_VARIABLE_NAME}
rem system environment
reg delete "HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment" /f /v {ENVIRONMENT_VARIABLE_NAME}
set emptyWord=
rem remove from local environment path
FOR /F "skip=2 tokens=2,*" %%A IN ('reg query "HKCUEnvironment" /v "Path"') DO set "localPath=%%B"
call set newPath=%%localPath:%{OLD_PATH}%=%emptyWord%%%
reg add "HKCUEnvironment" /f /v Path /t REG_SZ /d "%newPath%"
rem remove from system environment path
FOR /F "skip=2 tokens=2,*" %%A IN ('reg query "HKCUEnvironment" /v "Path"') DO set "systemPath=%%B"
call set newPath=%%systemPath:%{OLD_PATH}%=%emptyWord%%%
reg add "HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment" /f /v Path /t REG_SZ /d "%newPath%"
参考