1

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?

Mark Deven
  • 1,769

1 Answers1

1

A scalable and simple way to make a batch script accessible like an implicit command

  1. 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 PATH environment variable (e.g. C:\LinkScripts).

  2. 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 PATH environment variable (see How do I set or change the PATH system variable?).

  3. Open a new instance of command prompt once PATH adjustments 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

    1. In Search, search for and then select: System (Control Panel)
    2. Click the Advanced system settings link.
    3. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
    4. 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.
    5. Reopen Command prompt window, and run your java code.

    Windows 7

    1. From the desktop, right click the Computer icon.

    2. Choose Properties from the context menu.

    3. Click the Advanced system settings link.

    4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

    5. 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.

    6. Reopen Command prompt window, and run your java code.

    source

  • MKLink