Using mklink /h results in "Access is denied."

35

5

From command prompt with Administrator privilages:

c:\>mklink /h c:\dirA c:\Users\Piotr\dirB
Access is denied.

I'm on Vista x64. Using /j or /d instead of /h works. What's the problem?

Related:

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

Piotr Dobrogost

Posted 2011-03-29T21:14:10.180

Reputation: 4 413

Not sure if this is what you're after, but I tried mklink w/o any flags to try to link a directory and it didn't give me what I wanted. I tried using the \D flag and that seemed to work (not sure if that's different than \d or the default, which some ms docs said was 'symbolic'). – jinglesthula – 2014-07-02T16:12:22.293

Answers

47

Hard links can only be used for files, not directories.

References: MSDN: Hard Links and Junctions, <1>, and <2>

David d C e Freitas

Posted 2011-03-29T21:14:10.180

Reputation: 3 498

I did create a hard link for a folder once before. i guess it wasn't hard link it was a /d . it will do the exact for me. – Mahdi Rafatjah – 2016-05-27T12:22:19.177

7"Access is denied."... Not the most helpful error message here. – P-Gn – 2018-06-11T16:44:49.277

15

You can use the /j switch to create a directory soft link. Be careful with the del command. To remove link to directory use the rmdir command, as del will delete all files in the directory the link points to.

labiol

Posted 2011-03-29T21:14:10.180

Reputation: 159

2

As far as I know hard links are allowed for files only, not directories. http://technet.microsoft.com/en-us/library/cc753194(WS.10).aspx

Zord

Posted 2011-03-29T21:14:10.180

Reputation: 21

0

I had the same issue: check that the file or folder that you are trying to create doesn't already exist (c:\dirA).

David d C e Freitas

Posted 2011-03-29T21:14:10.180

Reputation: 3 498

Permissions on the root of the drive (C:) are slightly different to normal user folders, as it's a sort of "system" area in windows. – David d C e Freitas – 2017-03-19T17:58:58.720

@fnt Oh, because it's two different possible reasons or fixes for the issue. One more popular than the other. – David d C e Freitas – 2017-03-23T20:43:16.003

@DaviddCeFreitas No, it is not. There is no such thing as a hard link to a directory. There is no fix for "Access Denied" message when /h switch is used. The access permissions has nothing to do with this. – UnclickableCharacter – 2017-03-23T22:39:07.437

1Folder c:\dirA does not exist. – Piotr Dobrogost – 2011-04-08T21:15:16.503

OK, in this case, it's probably because it's being created on the root of c:, see if creating it in another directory helps? – David d C e Freitas – 2011-04-09T07:19:17.077

1I see nothing special about c:\ in this case. – Piotr Dobrogost – 2011-04-09T13:50:11.533