Why can't I make a symbolic link (mklink) even when I'm an administrator

45,800

Solution 1

You need to run mklink from an elevated shell (Right-click the Command Prompt shortcut, Run As Administrator).
If you are running mklink from an elevated shell, check the permissions on the directory and make sure there aren't any explicit Deny permissions set for the Administrators group.

Note: Make sure you're not trying to create a link where a directory containing files already exists, and are not accidentally creating a recursive set of links.

Solution 2

I ran into the same problems:

At first I got this error: You do not have sufficient privilege to perform this operation

And after retrying using an elevated cmd, I ran mklink /D linkToDir C:\temp\otherLink and received this error: Cannot create a file when that file already exists.

Turns out there was a (broken?) symlink there, marked as System:

attrib *

A  S  C:\temp\linkToDir

So FYI, check that there's not a Hidden (actually System) file using that name from a previously broken symlink creation.

That is what I wanted to highlight here.

Solution 3

I ran into the same problem and just managed to get it working. I was trying to force itunes to backup on another (larger) drive (C is an SSD).

Say you want to go from c:\dir1\dirToRedirect to d:\dirToRedirectTo, then:

Make sure dirToRedirect does not exist, because Windows is gonna create a link of the same name, which creates a naming conflict. So, delete dirToRedirect, create dirToRedirectTo, and run mklink /j "c:\dir1\dirToRedirect" "d:\dirToRedirectTo"

Share:
45,800

Related videos on Youtube

Ben
Author by

Ben

Updated on September 18, 2022

Comments

  • Ben
    Ben almost 2 years

    When I run mklink /D "C:\Users\bwilliams\AppData\Roaming\Sublime Text 2" "C:\Users\bwilliams\Dropbox\Sublime Text", I get this error `You do not have sufficient privilege to perform this operation.

    Why not? I'm administrator, and just want to create a link in my own Users\bwilliams directory to another folder in my Users\bwilliams directory? What am I doing wrong here?

    Thanks.

    • Mark E. Haase
      Mark E. Haase about 12 years
      Hilarious. I'm trying to do the same exact thing -- sync dropbox settings on Windows -- and I'm completely stymied why creating symlinks is not a default privilege for average users. I own the source and the target, and they are both underneath my home directory. Why is this restricted?!
    • Mark E. Haase
      Mark E. Haase about 12 years
      I was able to do this using mklink /J instead of mklink /D. Nothing has blown up... yet...
    • EKW
      EKW almost 8 years
      @mehaase Old comment, but... you can hose things with a poorly-placed junction, this is to protect from inadvertently doing that. The referenced, not at all a duplicate and I don't understand why the duplicate tag is still there today, question explains how to add that permission to a user.
  • Ben
    Ben over 12 years
    I ran it as Administrator and now it give the error Cannot create a file when that file already exists. So I deleted the Dropbox Sublime Text directory and tried it again and got the same message. Do you know what's wrong?
  • mtone
    mtone over 12 years
    @Ben The error is likely about the "Dropbox Sublime Text 2" directory, which is the link name being created. Make sure there's no folder or file with that name (there could be a file if you tried it without the /D at some point).
  • Ben
    Ben over 12 years
    There is no such file or directory. And the only permissions thing that I can see is that "Special permissions" are not Allowed (or Denied) for Administrators, System, or my bwilliams user account. I can't seem to figure out how to "check" special permissions.
  • EKW
    EKW over 12 years
    @Ben What is the Source Directory (The real directory) and what is the Target Directory (The symbolic directory)? I think you may be entering the parameters backwards.
  • Ben
    Ben over 12 years
    @EKW, well, now I'm not sure. By default, the Sublime Text 2 program I'm using stores stuff in the AppData\Roaming\Sublime Text 2 directory. But I want to "trick" Sublime Text into thinking that the Dropbox's "Sublime Text" directory is actually the AppData\Roaming\Sublime Text 2 directory. Once linked correctly, all the files will actually live in the Dropbox\Sublime Text directory.
  • Ben
    Ben over 12 years
    It turns out the directory I needed to delete was the original AppData\Roaming\Sublime Text 2 Directory. makes sense now that I did it.