Executable files like findstr.exe are placed in the \system32 folder and can be accessed anywhere from the command prompt. However doing this with one of my batch files only works in certain CDs. How can I turn my bat file into a command on Windows 10?
- 42,624
- 1,769
1 Answers
A scalable and simple way to make a batch script accessible like an implicit command
Create a new folder on the system where you want the scripts to be accessible from "anywhere" from the command prompt, and then set this folder in the
PATHenvironment variable (e.g.C:\LinkScripts).Use MKLink to link the actual scripts in others locations, and create a symbolic file link to each script to the new folder you created and added to the
PATHenvironment variable (see How do I set or change the PATH system variable?).Open a new instance of command prompt once
PATHadjustments are made and now when you type in the name of the script and press enter, it will run that batch file logic of the batch file(s) you linked with MKLink.
Batch Examples
md C:\LinkScripts
mklink C:\LinkScripts\test.cmd C:\Actual\Script\Folder\test.cmd
mklink C:\LinkScripts\pest.cmd C:\Colder\Script\Bolder\pest.cmd
mklink C:\LinkScripts\zest.cmd C:\Different\Script\Shoulder\zest.cmd
Results
Now you can open a new command prompt and run zest, test or pest with or without the appended .cmd (or .bat) file extension and it will run whatever logic is in each. This will allow you to easily be able to run a simple command for each or any newly added scripts which you need to use in this manner.
Further Resources
How do I set or change the PATH system variable?
Windows 10 and Windows 8
- In Search, search for and then select: System (Control Panel)
- Click the Advanced system settings link.
- Click Environment Variables. In the section System Variables, find
the
PATHenvironment variable and select it. Click Edit. If thePATHenvironment variable does not exist, click New. - In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
- Reopen Command prompt window, and run your java code.
Windows 7
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the
PATHenvironment variable and select it. Click Edit. If thePATHenvironment variable does not exist, click New.In the Edit System Variable (or New System Variable) window, specify the value of the
PATHenvironment variable. Click OK. Close all remaining windows by clicking OK.Reopen Command prompt window, and run your java code.
- 42,624