Windows Vista/Windows 7 Junctions (Access Denied “Problem”)

7 11 2009

All I wanted to do was sit down, watch some Andromeda episodes, and drink my Monster Energy drink. Windows 7 decided to be confusing and kill 10 minutes of my time reading about the NTFS file system though, so I thought I’d blog about my findings.

It all started when I wanted to access My Videos. I went into my Documents “Library” in Windows 7, clicked on My Videos, and got an access denied error. Then I went in a little deeper and found,

C:\users\PherricOxide\Videos\ really exists.

C:\users\PherricOxide\My Videos\ is what’s shown in Explorer. This works when clicked.

C:\users\PherricOxide\My Documents\My Videos\ gives an access denied error.

The explanation? NTFS Junction Points. It’s a type of Reparse Point like symbolic links to files or mount points. In simple terms, a shortcut to a directory. This isn’t the same as the Windows Shell Shortcut though, like you would create with a new -> shortcut button. Junction points act entirely like the directory they point to.

For example, Vista and Windows 7 have a Junction “C:\Documents and Settings\” which points to “C:\users” to add legacy support for old applications now that the user data has been moved to a new location. If you move a file foo.txt into “C:\Documents and Settings\PherricOxide\” it will really move it into “C:\users\PherricOxide\”. This allows older applications to read, write, and modify files inside “Documents and Settings” without ever knowing it doesn’t exist anymore. Nifty, huh?

Now the odd part is the “Access Denied” messages when you try and access a Junction inside Vista or 7. The reason for this is that the file permissions are set so that you can’t list the files inside the these Junction/Directories. If you change the permissions or take control of the junction you can, but I wouldn’t advise it, because this is actually a feature and not a bug. The reason is that programs like virus software, backup software, or anything else that scans your entire drive likely wouldn’t realize they are traversing a junction. Using the above example during a virus scan, the scanner would scan both “C:\users\PherricOxide\foo.txt” and “C:\Documents and Settings\PherricOxide\foo.txt” for viruses, and waste quite a bit of time. To avoid this, permissions have been set up so all the Junctions in Vista and Windows 7 can’t be opened and listed, but the files inside can still be modified if you know the exact path to them.


Interesting notes,

  • To view the junctions with the command prompt, you can run dir /aL in a folder. This is also the easiest way to see where a Junction points. Just a normal dir won’t show them.
  • To view all the junctions in your computer, dir /aL /s > c:\JunctionsList.txt
  • Someone finally came to their senses and got rid of all the My this and My that crap in the file system, plus spaces in tons of file names, yay! Unfortunately for the user, they still think they see it all, due to collections of junctions, symlinks, and Libraries for reverse comparability and new features.
  • In Windows Explorer, Junction points are indicated with an arrow icon
  • Deleting a Junction in Windows Vista and 7 is usually safe, but in XP or 2000 will likely delete the contents of the folder that the Junction points to.




11 responses

2 12 2009

This is great info. Now, the problem I have, is I deleted “My Music”, which if I understand you is a junction. iTunes really,really wants this; but it would appear that making a shortcut is not the same thing. How would I *restore* this junction?

Thanx again.

3 12 2009

So here’s the deal:

If you delete (put in trash) things in a directory pointed to by a junction, then delete the junction, the things in the recy bin cannot be restored (until, I suppose, the junction is recreated).

Also, you will not be able to restore them from history either (as the history used the junction rather than the actual path to store them).

Lastly: the issue I had, turned out to be related to the deleted files (the ones iTunes wanted) being included in the “Music Library” under Desktop->Libraries.

To fix: I created a new “My Music” junction, pointed it to c:\Users\Blah\Music, and adding this junction to the Music library, and I was able to reinstall iTunes to make everything work again.

I hindsight, once I recreated the junction, I should have been able to suck the files outta the recy bin, but I had deleted them by that time (since I couldnt restore them).

Then I installed MediaMonkey.

5 12 2009

Not so fast (or simple) I love junctions (they feel good to my linuxish nature). I’ve been using them a lot for my own purposes in XP.

Now that I’m setting up the new Windows 7 box, there is some kind weirdness happening here. If I run CMD as Administrator I can easily navigate to the folder “Documents and Settings” and list the folder contents, but when I run Explorer as Administrator I can’t.

11 12 2009

Nick, interesting. When I cd to Documents and Settings on my Windows 7 box and list the folder contents, it gives,

C:\Documents and Settings>dir
Volume in drive C is Win7
Volume Serial Number is 1800-8C66

Directory of C:\Documents and Settings

File Not Found

20 10 2010

hey, thanks for the info. i do have a question though, and don’t tease me about not knowing this, but is foo.txt a harmful thing to have on a computer (something that needs to be deleted) or is it harmless? plz reply

30 10 2010

No.. it’s just an example file. Programmers use foo and bar for examples of variables in code when the variables don’t really have any meaning outside the example.

23 06 2011

Useful information. I ran into this problem when trying to use xcopy to backup “Documents”.

20 09 2011

can i ask what kind of IDIOT sets up a Infinate loop on purpose, to avoid leaving the old folders for the old programs to reside in?
the MS sysem has folders galore, and many many leftover folders from way way back, why would anyone choose this insane methodology , and set thier system up for a complete failure?
didnt Windows sytems have enough Infinate loop errors to 10 years later Purposfully set one up in the system?

Did anybody THINK before they chose that method for this situation?

4 02 2012

I agree with Philharmonic. The old My documents, my this, etc. was lame, but the solution they came up with is just crap. I accidentally gained access to the Junction for Application Data, and next thing you know, I have many, many nested copies of Application Data. Junction boxes run amok.

29 02 2012

Thanks for the info. I had a hard time believing that this is what they did, for as Jim and Philharmonic point out, it is an insane approach [I’ll avoid the term “solution”]. Now I have unwanted “redundant” files all over the place after copying my files over to a new machine.

5 08 2012

Just the explanation that I was looking for, thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: