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

后端 未结 17 2597
没有蜡笔的小新
没有蜡笔的小新 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 02:54

    Use a 1 line batch file in your install:

    SETX PATH "C:\Windows"
    

    run the bat file

    Now place your .exe in c:\windows, and you're done.

    you may type the 'exename' in command-line and it'll run it.

    0 讨论(0)
  • 2020-11-28 02:55

    You may also permanently (after reboots) add to the Path variable this way:

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

    Reference: Change System/User Variables

    0 讨论(0)
  • 2020-11-28 02:56

    Rather than putting the executable into a directory on the path, you should create a batch file in a directory on the path that launches the program. This way you don't separate the executable from its supporting files, and you don't add other stuff in the same directory to the path unintentionally.

    Such batch file can look like this:

    @echo off
    start "" "C:\Program Files (x86)\Software\software.exe" %*
    
    0 讨论(0)
  • 2020-11-28 02:56

    Let's say my exe is C:\Program Files\AzCopy\azcopy.exe

    Command/CMD/Batch

    SET "PATH=C:\Program Files\AzCopy;%PATH%"
    

    PowerShell

    $env:path = $env:path + ";C:\Program Files\AzCopy"
    

    I can now simply type and use azcopy from any location from any shell inc command prompt, powershell, git bash etc

    0 讨论(0)
  • 2020-11-28 02:57

    Should anyone be looking for this after me here's a really easy way to add your Path.

    Send the path to a file like the image shows, copy and paste it from the file and add the specific path on the end with a preceding semicolon to the new path. It may be needed to be adapted prior to windows 7, but at least it is an easy starting point.

    Command Prompt Image to Export PATH to text file

    0 讨论(0)
  • 2020-11-28 02:59

    Another way could be through adding .LNK to your $PATHEX. Then just create a shortcut to your executable (ie: yourshortcut.lnk) and put it into any of the directories listed within $PATH.

    WARNING NOTE: Know that any .lnk files located in any directories listed in your $PATH are now "PATH'ed" as well. For this reason, I would favor the batch file method mentionned earlier to this method.

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