Kae Travis

Create a Symbolic Link from a Custom Action

Creating a symbolic link can be achieved using the MKLINK internal command. Internal commands are native to the windows command shell and are NOT executable files. As such, we must call these commands via the windows command shell as follows:

Let’s pretend we have a physical folder in C:\Program Files\AlkaneSolutions but we want to create a symbolic link to it in the root of C:\ called ‘AlkaneSolutions’. I would use the following MKLINK command:

MKlink /D C:\AlkaneSolutions "C:\Program Files\AlkaneSolutions"

From a custom action we should do 2 things:

1. We cannot call MKLINK directly since it’s an internal command and not an executable. So instead we call CMD.exe with the /c parameter (/c runs the command and then terminates the command prompt) and then pass the MKLINK command afterwards.

2. We should not include any hardcoded paths, and instead try to use windows installer properties where possible. Remembering to enclose any paths in quotes!

As such, and when scheduling the Custom Action to run in a deferred context just before InstallFinalize, our Custom Action should look similar to this:

MKLINK commandThe action ‘MKLINK’ is merely the name of our Custom Action. The Type relates to the type of custom action and its execution options. The Source of [SystemFolder] relates to the location of CMD.exe. And the Target is the command we want to run.


Create a Symbolic Link from a Custom Action
Create a Symbolic Link from a Custom Action

Leave a Reply