“Register” an .exe so you can run it from any command line in Windows

后端 未结 17 2612
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 02:38

How can you make a .exe file accessible from any location in the Windows command window? Is there some registry entry that has to be entered?

17条回答
  •  执念已碎
    2020-11-28 03:05

    Simple Bash-like aliases in Windows

    To get global bash-like aliases in Windows for applications not added to the path automatically without manually adding each one to the path, here's the cleanest solution I've come up with that does the least amount of changes to the system and has the most flexibility for later customization:

    "Install" Your Aliases Path

    mkdir c:\aliases
    setx PATH "c:\aliases;%PATH%"
    

    Add Your Alias

    Open in New Shell Window

    To start C:\path to\my program.exe, passing in all arguments, opening it in a new window, create c:\aliases\my program.bat file with the following contents(see NT Start Command for details on the start commmand):

    @echo off
    start "myprogram" /D "C:\path to\" /W "myprogram.exe" %*
    

    Execute in Current Shell Window

    To start C:\path to\my program.exe, passing in all arguments, but running it in the same window (more like how bash operates) create c:\aliases\my program.bat file with the following contents:

    @echo off
    pushd "C:\path to\"
    "my program.exe" %*
    popd
    

    Execute in Current Shell Window 2

    If you don't need the application to change the current working directory at all in order to operate, you can just add a symlink to the executable inside your aliases folder:

    cd c:\aliases\
    mklink "my program.exe" "c:\path to\my program.exe"
    

提交回复
热议问题