3

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 1

0

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
  • 1
    Note that on Windows, mklink is a "shell built-in" command that's only available within Cmd (e.g. cmd /c mklink) and not directly through PowerShell. (The latter has its own cmdlets for creating links, though they can't do relative symlinks.) Commented Nov 22, 2021 at 14:29
  • Thanks, but that does not work for my use case, as DLL loading is broken when I invoke the .exe via the link. I edited the question to include that information.
    – sebbraun
    Commented Nov 23, 2021 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .