I'm setting up a custom command line utility, and the 'installer' adds a PATH entry. It works after this for the current session. After I close and open the command prompt, the PATH is reset and the command line isn't available any more. What's this about and how do I permanently set it from CMD?
Permanently setting PATH from CMD windows 8
batchbatch filecmd.exe
Related Solutions
How do I copy/replace files from a relative path to a .lnk target location?
Use the following batch file:
@echo off
setlocal
rem get the .lnk target directory
for /f "tokens=* usebackq" %%i in (`type "C:\Users\Home\Desktop\Example.lnk" ^| find "\" ^| findstr/b "[a-z][:][\\]"`) do (
set _targetdir=%%~dpi
)
rem copy the files
copy /y file1.exe %_targetdir%
copy /y file2.exe %_targetdir%
endlocal
My code gives an error "the syntax of the command is incorrect".
You are missing the
"
afterlnk
in thefor
command.%_target%
should be%_targetdir%
(that was a mistake in my batch file - now fixed).
Here is the corrected version of your batch file:
@echo off
setlocal
rem get the .lnk target directory
for /f "tokens=* usebackq" %%i in (`type "C:\Users\Abdo\Desktop\Gravity.lnk" ^| find "\" ^| findstr/b "[a-z][:][\\]"`) do (
set _targetdir=%%~dpi
)
rem copy the files
copy /y Gravity.pdf %_targetdir%
endlocal
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- find - Search for a text string in a file & display all the lines where it is found.
- findstr - Search for strings in files.
- parameters - A command line argument (or parameter) is any value passed into a batch script.
- set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
- type - Display the contents of one or more text files.
- for /f - Loop command against the results of another command.
To delete variables in the current cmd
instance, do this:
set http_proxy=
set https_proxy=
or (even better):
set "http_proxy="
set "https_proxy="
To delete variables for future cmd
instances, do this:
setx http_proxy ""
setx https_proxy ""
Best Answer
How do I permanently set the
PATH
from acmd
shell?You need to use
setx
instead ofset
.Example:
Notes:
"
s are recommended in case any of the path elements contain spaces.cmd
shell should be run as Administrator./m
to set thePATH
in the system environment instead of the user environment.Warning:
PATH
is allowed to be without errors.Further Reading