The Computer Oracle

Add a single exe in given directory to PATH environmental variable

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island Looping

--

Chapters
00:00 Add A Single Exe In Given Directory To Path Environmental Variable
00:32 Accepted Answer Score 15
02:05 Answer 2 Score 3
02:25 Answer 3 Score 2
02:59 Answer 4 Score 0
03:28 Thank you

--

Full question
https://superuser.com/questions/513932/a...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #path #environmentvariables

#avk47



ACCEPTED ANSWER

Score 15


(Note: I know this is almost 3 years old, but I landed on this page by searching a similar question, so I'm writing the correct answer here for anybody else coming here)

Yes, it is possible, it's even preferred to do this instead of cluttering the PATH variable. You need to add a key under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths (for the machine) or HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths (for the user - preferred).

The format is the same in both cases, the key name should be utility-5.exe and the registry default value should be D:\utils\utility-5.exe.

There are more information (including several more stuff you can do) on MSDN and by Raymond Chen

EDIT: (some years later):

This won't (by design) work with Command Prompt (cmd) or PowerShell. In the case of PowerShell, you'll want to add a new alias in your $PROFILE, like so:

Set-Alias -Name vlc -Value 'C:\Program Files\VideoLAN\VLC\vlc.exe'

In the case of Command Prompt (cmd.exe), there's similar functionality with DOSKEY:

DOSKEY vlc="C:\Program Files\VideoLAN\VLC\vlc.exe"

This way you don't need to deal with the PATH variable at all.




ANSWER 2

Score 3


You can't add a single executable to the path. There may be an alternative to moving it to another directory, though - assuming it's on an NTFS partition, you could create a symlink to the executable in a directory that is in the path using the mklink command.




ANSWER 3

Score 2


You will have to put it into a directory.

All the entries in your PATH variable must be directories to be useful. cmd.exe and any other shell or application that uses PATH will try to find the executable corresponding to any command you type by pasting the name of command onto the end of each PATH directory in turn until it either finds the command you asked for or it runs out of directories in your PATH. Any entry that doesn't exist or isn't really a directory will never match anything.




ANSWER 4

Score 0


One potential solution is to create a separate directory that you add to %PATH% and then use a symbolic link to include the .exe file within said directory.

However if the .exe needs external files (like a .dll) to operate, you'd need to include that in the directory as well.

If you choose to do this I recommend the Link Shell Extension tool for Windows so you don't have to make the symbolic links in the command prompt.