Access is denied error, when I mklink on Windows 7 [duplicate]
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?
Important points:
- You need to run as admin if UAC is on. (or at least security policy to allow creation of links).
- The
/D
switch needs to be used if the link is for directory. - First parameter is a link, second parameter is the original folder.
- Link should not exist already.
Usage:
mklink /D c:\users\me\new_link\ c:\users\me\original_folder\
I found an answer from this site. In short, I should have run cmd.exe as Administrator.
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.
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.
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