20

In Linux/Unix, the command to create a symbolic link is called ln. The user doesn't need any special privileges to use it. In the Windows (from 7 onwards) the equivalent is called mklink. It can be issued from the cmd prompt but the user needs to be admin.

I find it quite useful to have symbolic links that I can just rename to pick up different code bases on different variants of the same project.

Is there a setting somewhere like a group policy of some sort that allows non-admin users to use mklink or is it just not allowed because it does something dodgy to the file system?

Edit

Non admin users can make directory links using mklink /J

cup
  • 7,589
  • 4
  • 19
  • 42
  • In Linux/Unix there's an admin user for which a input/prompt is displayed whenever 'elevated' privileges are required. In Windows it's not really much different, If Windows has decided it requires elevated privileges, then you need to run it with such elevation. In [tag:cmd] open the prompt 'as administrator', with a [tag:batch-file], either run it 'as administrator' or create a shortcut to it and set the elevation as part of the shortcut. If your issue is that you're not allowed to run admin commands, then there's no way you can bypass the restriction. – Compo Sep 21 '19 at 09:21
  • 4
    My issue is why it is a restricted command – cup Sep 21 '19 at 18:30
  • If you have Windows 10 and turn on Developer Mode, you may be able to create Symbolic Links without being admin, but other than that, I'm afraid that Microsoft has decreed it. I have no knowledge of a command, setting or registry key/value, which can offer that functionality in earlier OS's, unless possibly elevating the level of the end user, essentially giving them more access rights. – Compo Sep 21 '19 at 20:00
  • 1
    Interesting - it does work in developer mode. @Compo - if you change your comment to an answer, I'll accept it. – cup Sep 22 '19 at 08:12

5 Answers5

19

If you have Windows 10, and turn on Developer Mode you may be able to create Symbolic Links without requiring admin privileges.

Window 10 Developer Mode

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 3
    where can I find this menu? – mcExchange Aug 20 '21 at 11:41
  • 4
    From a Command Prompt window, you could try `start ms-settings:developers`. To access it directly from the GUI, it should be under Settings -> Update & Security -> For Developers _(left panel)_. – Compo Sep 08 '21 at 11:31
  • Note that the wording for option might inidicate that it's _only_ about installing apps, "Install apps from any source, inlcuding loose files", but that's not the case. Turning it on does allow symbolic links without admin. (For me anyway, Microsoft Windows [Version 10.0.19041.1415]). I did not find a means to enable sym links but still keep app install restricted. – matt wilkie Feb 03 '22 at 16:50
  • 2
    This works - _instantly_: once I flipped the switch I re-ran the same `mklink` command and it worked. Do we know what registry-keys or other system-settings this Settings widget controls so we don't need to flip it manually? – Dai Aug 09 '22 at 08:19
  • @Dai, you could try the method used [in this answer](https://stackoverflow.com/a/44160849). But be aware that you will need to run that elevated, i.e. 'Run as administrator', which would essentially make such advice contrary to the point of this question. – Compo Aug 09 '22 at 10:12
10

You can set this in gpedit.exe:
(I don't know the exact English terms for that)

 <computer configuration>
   <Windows settings>
     <security settings>
       <local policy>
         <user rights>
           <creating symbolic links>

There you can insert any user you want.

Konrad
  • 321
  • 2
  • 4
  • 1
    Problem is being able to use the group policy editor. On most systems, you need to be admin to used the group policy editor. In corporate environments, this is not normally allowed. – cup Nov 30 '21 at 10:18
  • That is true, but because changing system privileges' requires admin rights, this is the only way this can be done. – PatS Feb 01 '22 at 00:52
  • I'm trying to use nvm on windows from CoreyButler (see https://github.com/coreybutler/nvm-windows/releases) and the `nvm use` command requires rights to create a SymlinkD (symlink to a directory) and that doesn't work without admin rights. I tried this solution and it didn't work. Do you have to logout and back on to get this right? So I enabled developer mode using `start ms-settings:developers` and after enabling developer mode, the the `nvm use` command would work, and the symlink was created. – PatS Feb 01 '22 at 01:05
  • This approach definitely works for developers who have admin access to the computer, but normally work under a standard user account, cause this is more secure. Run `gpedit.msc` under an admin account. Enable the creation of the symbolic links for the necessary user or groups (by default only Administrators are in the list of privileged users). After that you will need to restart the system. And then voila, you should be able to create symbolic links with the `mklink` command. – Andrew Aug 03 '22 at 02:24
3

If the target is also local and a directory, e.g. if you want to map <ProjectDir>\SubComponentVersion1\src\Project1 to <ProjectDir>\src\Project1 to later easily replace that subcomponent version mkdir /j can be used instead.

There are some differences between the two, but to create links within a source repository and possibly different submodules mkdir /j should be fine to use. Unlike mkdir /d it does not require admin rights.

PMF
  • 14,535
  • 3
  • 23
  • 49
0

I'm answering this with regards to an error that I encountered while using the Sublime Text 3 editor along with MikTeX and Sumatra PDF viewer.

Error

"--mklinks requires admin mode (--admin)"

To get rid of this do the following:

  1. Open the MikTeX Console(Win+Search("MikTeX Console")).
  2. Click "Switch to administrator".
  3. Upgrade if any.

Recompile in Sublime text.

  • 3
    The problem is being able to do it without switch to administrator. In work environments, very often, we are unable to switch to administrator. – cup Nov 25 '21 at 23:35
0

Hard links are better than Symlinks plus they don't need admin:

mklink /H (link) (file)