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

后端 未结 17 2632
没有蜡笔的小新
没有蜡笔的小新 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:00
    • If you want to be able to run it inside cmd.exe or batch files you need to add the directory the .exe is in to the %path% variable (System or User)
    • If you want to be able to run it in the Run dialog (Win+R) or any application that calls ShellExecute, adding your exe to the app paths key is enough (This is less error prone during install/uninstall and also does not clutter up the path variable)
    0 讨论(0)
  • 2020-11-28 03:04

    it's amazing there's no simple solution for such a simple task on windows, I created this little cmd script that you can use to define aliases on windows (instructions are at the file header itself):

    https://gist.github.com/benjamine/5992592

    this is pretty much the same approach used by tools like NPM or ruby gems to register global commands.

    0 讨论(0)
  • 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"
    
    0 讨论(0)
  • 2020-11-28 03:05

    It is very simple and it won't take more than 30 seconds.

    For example the software called abc located in D:/Softwares/vlc/abc.exe Add the folder path of abc.exe to system environment variables.

    My Computer -> Click Properties -> Click Advanced system settings -> Click Environment Variables

    Click on Ok.

    now you can just open cmd prompt and you can launch the software from anywhere. to use abc.exe just type abc in the command line.

    0 讨论(0)
  • 2020-11-28 03:06

    You can add the following registry key:

    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myexe.exe
    

    In this key, add the default string value containing the path to the exe file.

    0 讨论(0)
  • 2020-11-28 03:07

    The best way to do this is just install the .EXE file into the windows/system32 folder. that way you can run it from any location. This is the same place where .exe's like ping can be found

    0 讨论(0)
提交回复
热议问题