# Access is denied error, when I mklink on Windows 7

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?

-

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.

-
this link is not very useful. (pun unintended) –  ragu.pattabi Sep 11 '12 at 14:49
This answer does not seem relevant to the question. –  kreemoweet Nov 3 '12 at 6:58

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

-

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

-

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.

-

If you run:

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

-
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. –  Software Monkey Feb 9 at 1:02

In Windows 7 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 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.

-

For directories you have to do:

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

-
mklink /D c:\users\me\new_link\ c:\users\me\original_folder\