34

My home directory is c:\Users\phi as a user phi, and I made a directory at c:\Users\abc. I need to symbolic link from c:\Users\phi\hello to c:\Users\abc\hello.

I run the following command

mklink c:\Users\abc\hello c:\Users\phi\hello

But I get the Access is denied error. User phi is Administrator, so I have no problem writing files in c:\Users\abc.

Why is this? How to mklink?

10 Answers 10

28

Important points:

  1. You need to run as admin if UAC is on. (or at least security policy to allow creation of links).
  2. The /D switch needs to be used if the link is for directory.
  3. First parameter is a link, second parameter is the original folder.
  4. Link should not exist already.

Usage:

mklink /D c:\users\me\new_link\ c:\users\me\original_folder\
  • @LawrenceDol Is it right to say that for non-admin users, you need the special permission (SeCreateSymbolicLinkPrivilege), while for admin-users you need to elevate with run-as-admin. But then is it possible to also set SeCreateSymbolicLinkPrivilege on an admin-user and avoid having to elevate with run-as-admin? This question: stackoverflow.com/questions/29956470/… indicates that for admin-users to not need to elevate, UAC must be disabled. – CMCDragonkai Dec 14 '16 at 11:29
  • @CMCDragonkai: I don't think elevation is necessary, but I haven't specifically tested that. It seems to me that I have created links using an admin account in a normal command window before and I always leave UAC on. – Lawrence Dol Dec 14 '16 at 19:02
25

I found an answer from this site. In short, I should have run cmd.exe as Administrator.

  • 4
    For reference, this can also be a cause: superuser.com/questions/264181/… – Wouter Jun 29 '16 at 10:11
  • 9
    If you try to use the /H parameter when you're linking folders you will get Access is Denied. You need use /D alone for folders. This is what is contained in Wouter's link. +1 to Wouter, thanks mate! :) – CausingUnderflowsEverywhere Sep 20 '16 at 13:49
21

Note that the same error will be presented when you try to create junctions on mapped drives. I was pulling my hair out on this until I came across the examples on this page on MSDN Hard Links and Junctions.

Short answer: you can only use mklink on local volumes.

  • this link is not very useful. (pun unintended) – rpattabi Sep 11 '12 at 14:49
  • This answer does not seem relevant to the question. – kreemoweet Nov 3 '12 at 6:58
  • 2
    @kreemoweet the answer is relevant because if you get an "Access is denied error, when I mklink on Windows 7", the reason may be that you are not using the command on a local volume. – Reg Edit Mar 23 '17 at 14:47
  • Yes you can use mklink beyond local volumes. mklink /d link_name \\server\share works just fine. – UnclickableCharacter Jul 3 at 20:55
  • You can't make them on a mapped drive. Local disk -> Remote? Yup. Party like it's Netware 2.x – rburte Jul 5 at 6:41
15

In Windows 7 (and later) you need a special security privilege to create links and junctions. As administrator you can grant this permission to users using secpol.msc to set Local Policies\User Rights Assignment\Create symbolic links.

If the user is logged on at the time, they will need to log off and back on to be able to create links.

Note the caution that links can expose security weaknesses in some apps - I have not researched what those weaknesses might be.

  • This is the only eligible answer to this problem for any answer isn't getting down to the nitty gritty. Stop working as Administrator! This is a very XP-ish attitude demonstrating lack of awareness for security risks any Windows is proned to a lot. – Thomas Urban May 1 '17 at 10:05
9

If you're frequently using Linux, remember that the parameters are swapped on Windows.

If you use the wrong order, you'll get an "Access Denied", too. Because you're trying to create a symbolic link where the original already exists.

Windows: mklink /D link original

Linux: ln -s original link

4

I was getting this because I accidentally ran mklink /D against a file. The link wasn't showing in explorer but it did in Windows Explorer. Using the Command Prompt I deleted the original invalid directory link and then recreated it without the /D option.

By the way, I was getting the "Access is denied" error even though I was running cmd.exe as an administrator.

1

Apart from running mklink as Administrator you also should make sure that you have enough permissions to the destination folder you are linking to.

1

If you run:

mklink /j C:\path_to_link C:\destination

it should work. In my case, powershell and cmd produced the same output. For powershell you only have to start the command with

cmd /c mklink...

  • 3
    Yes, but beware: junctions are far more deadly than hard directory links. Deleting a link from command line or explorer simply removes the link, but deleting a junction from explorer removes everything in the directory and then deletes the junction - OOPS. Use mklink /D src tgt instead. – Lawrence Dol Feb 9 '13 at 1:02
0

This might sound weird, but check that the file or folder doesn't already exist that you are trying to create. Sometimes it's easy to overlook in the cmd prompt.

0

For directories you have to do:

mklink /D c:\Users\abc\hello c:\Users\phi\hello

Not the answer you're looking for? Browse other questions tagged or ask your own question.