This question already has answers here:
Append a directory to PATH Environment Variable in Windows
(3 answers)
Why are other folder paths also added to system PATH with SetX and not only the specified folder path?
(1 answer)
How to search and replace a string in environment variable PATH?
(1 answer)
Adding the current directory to Windows path permanently
(2 answers)
What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?
(4 answers)
Closed 3 years ago.
My PATH has few entries like %SystemRoot%, %USERPROFILE%/... etc which are pointing to another env variable. But when I update the PATH with command line, it replaces those env entries with actual value like e.g. below
Earlier Entry : %SystemRoot%;%USERPROFILE%\AppData
SETX MY_ENV "C:\MyData"
SETX PATH %MY_ENV%;%PATH%
Path Value : C:\MyData;C:\Windows;C:\USers\UserName\AppData
But, I am looking for a solution which can be run directly as cmd line por through Batch programming that will set my Path as below
%MY_ENV%;%%SystemRoot%;%USERPROFILE%\AppData
This is not the Path variable meant for logged in user but is the system path variable.
Related
This question already has answers here:
What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?
(4 answers)
Closed 2 years ago.
When I need to extract a .RAR file using a BAT script I use the following command:
set path="path\to\installed\winrar\directoy"
WinRAR x "name of file.RAR"
In the next line if I try to give a xcopy command it says:
'xcopy' is not recognized as an internal or external command, operable program, or batch file.
Whereas if I run the xcopy command before issuing the set path command, it works without any issue.
How do I use the xcopy command AFTER giving the set path command?
To better explain this in more detail.
Windows has environment variables for both System and User. one of these variables is path.
Path is used as a default indexing variable which tells the system where to find files and executables. So for you setting path, your cmd prompt no longer knows where to find the executables, unless you supply the full path to the executable BUT it should still never be done.
To understand it better:
open cmd and type set path or echo %path% and see the result.
Then do set "path=some string" then do set path or echo %path% again and notice how it changed.
So get to know your variables by running set from cmd to list all default variables, and ensure you do not use any of them when creating variables in batch-files. It can become VERY dangerous.
So, to wrap it up, to fix your issue, change path to something unique like mypath:
set "mypath=path\to\installed\winrar\directoy"
"%mypath%\WinRAR.exe" x "name of file.RAR"
This question already has answers here:
Get current batchfile directory
(4 answers)
Closed 3 years ago.
So basicly I want to make a batch file that can execute other files, while learing its own location on execution.
It should then use it own path as a reference to the other files.
How should I go about coding that or are there any guides for exactly that?
Thanks in advance!
The batch file name as entered via command line is stored in %0. Using file expander to get other parts. You can put the following code into a batch file and try it out:
REM print batch filename as user entered
echo %0
REM print full file name: d - drive, p - path, f - filename
echo %~dpf0
REM print path only
echo %~dp0
The current directory is stored in %CD%, in case you need it.
This question already has answers here:
Adding a directory to the PATH environment variable in Windows
(21 answers)
Adding environment variable from command prompt / batch file
(2 answers)
How to set PATH environment variable in batch file only once on Windows?
(2 answers)
Why are other folder paths also added to system PATH with SetX and not only the specified folder path?
(1 answer)
Adding the current directory to Windows path permanently
(2 answers)
Closed 4 years ago.
Is there a way to append a Registry key with a batch file? To be clear, I don't want to replace the key, I want to add to it.
Example:
Key Location: HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Change: C:\Windows;C:\Java
To: C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT
It's a REG_EXPAND_SZ, so [~] won't work, unless I'm doing it wrong.
https://msdn.microsoft.com/en-us/library/aa371168(VS.85).aspx
Save this to something.reg. Execute this with double click and you will set changes. This is maybe overwriting but I think this is better idea.
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT /t REG_SZ /f
This question already has answers here:
How can I pass arguments to a batch file?
(20 answers)
Closed 6 years ago.
I want to create a cmd command by writing a batchfile and put it into "system32" to call it in the cmd console by its name. Is there a way to expect parameters in the batch file:
Write in cmd:
fake-command Test
And then work with the string "Test" in the batch file?
Use %1 to access the first argument, %2 for the second, etc.
This question already has answers here:
'Pretty print' windows %PATH% variable - how to split on ';' in CMD shell
(12 answers)
Closed 7 years ago.
Can any share a batch script that prints each batch entry in a new row?
eg - if Path = C:\Python27;C:\Python27\Scripts
Then it shall get printed as
C:\Python27
C:\Python27\Scripts
I have a VBscript that does this:
Set oShell = CreateObject( "WScript.Shell" )
pathList = oShell.ExpandEnvironmentStrings("%PATH%")
dirs = Split(pathList, ";", -1, 1)
For i = 0 to UBound(dirs)
WScript.Echo dirs(i)
Next
Save it as e.g. list_path.vbs and you can use it just like any other batch file.
If you can't run it by entering list_path you need to adjust the value of PATH_EXT in order to include .vbs (but I think that is the default in modern Windows versions - I can't remember having to adjust that)