Windows Equivalent to symlinking executables into PATH

I want to have a certain executable available in my %PATH% under Windows. The catch here is that the tool is in a directory where there are a lot of other executables which I don't want to have in my PATH, so I can't just add the whole directory.

In my Linux systems, I would just symlink the executable into $HOME/bin, which is in $PATH, and it would get picked up from there. But on Windows, creating symbolic links is restricted to admin users and Microsoft warns about some vague security concerns, so I'm reluctant to play around with that.

What is the Windows equivalent to ln -s $SOME_EXECUTABLE_FILE $HOME/bin/?

I saw the Chocolatey solves that problem by generating shim executables, but their shimgen tool is proprietary and only licensed for use as part of their package manager.


Edit: Simply symlinking the executable like I would on a Linux system appears to break DLL loading. Here's what happens when I try symlinking an executable to a different folder on Windows:

C:\tmp>mklink ruby.exe C:\tools\msys64\mingw64\bin\ruby.exe
symbolic link created for ruby.exe <<===>> C:\tools\msys64\mingw64\bin\ruby.exe
C:\tmp>.\ruby.exe
### error dialog about not finding libgmp-10.dll and libssp-0.dll

The missing DLL files are in the bin directory. Apparently, Windows does not look in the "real" directory of an executable if the executable is invoked via a symlink. It works in the same CMD session when I invoke it via its full path:

C:\tmp>C:\tools\msys64\mingw64\bin\ruby.exe
puts 'Hello world'
^D
Hello world

1 Answer

You are looking for this:

mklink <Link path> <Tarket path>

mklink

Creates a directory or file symbolic or hard link.

Syntax

mklink [[/d] | [/h] | [/j]] <link> <target>

Parameters

  • /d - Creates a directory symbolic link. By default, this command creates a file symbolic link.
  • /h - Creates a hard link instead of a symbolic link.
  • /j - Creates a Directory Junction.
  • <link> - Specifies the name of the symbolic link being created.
  • <target> - Specifies the path (relative or absolute) that the new symbolic link refers to.
  • /? - Displays help at the command prompt.
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like