Scott Hanselman

Windows Vista, Junctions and moving My Documents to another drive.

September 29, 2006 Comment on this post [4] Posted in Musings
Sponsored By

I've blogged about Junctions (Reparse Points or "Hard Links") before, as has Travis with his Junction Shell Extension. Junctions are great for organizing your code because you can start using relative paths again, even when your project structure doesn't lend itself to relative paths. (Sometimes folks even SUBST a drive and "everyone builds to S:" to make this easier. I say ick to that.)

It seemed to me as I spread the word about the wonder and glory of Junctions (as was as the fantastic danger as in Windows XP SP2 when you delete a junction from Explorer, you delete what it points to!)

So, I was thrilled to notice some interesting and very cool new things regarding Junctions on Vista.

Vistajunction2First, in Vista now, deleting a junction point in Explorer doesn't delete the pointed-too folder. If you've used Junctions in Explorer, you'll realize this is huge.

Also, in Vista, while there's no way from Explorer to tell WHERE a junctions points to, either in the Properties or a Tooltip nor in the "Type" column in Details View (insert obvious feature request here) they at least include a Shortcut Icon Overlay on a Junction. It still says "Folder" when you look at it in Details, while a Shortcut to a Folder says "Shortcut." At least that's a start! In this screenshot the first icon is a folder while the second icon is a junction pointing to the first.

This got me thinking, since I keep all my data on a separate drive D: for "DATA." A lot of us do.

In Vista, "Documents and Setting" is now "C:\Users" and a lot of other stuff has changed. They MOVED my cheese. So, where did they move it, and how do they make things point to the newly moved stuff?

They use Junctions, making their first mainstream appearance! I went to C:\Users and did this:

C:\Users\Scott>dir /a /s | find /i "junction"
09/08/2006  01:23 AM    <JUNCTION>     Application Data [C:\Users\Scott\AppData\Roaming]
09/08/2006  01:23 AM    <JUNCTION>     Cookies [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Cookies]
09/08/2006  01:23 AM    <JUNCTION>     Local Settings [C:\Users\Scott\AppData\Local]
09/08/2006  01:23 AM    <JUNCTION>     My Documents [C:\Users\Scott\Documents]
09/08/2006  01:23 AM    <JUNCTION>     NetHood [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
09/08/2006  01:23 AM    <JUNCTION>     PrintHood [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
09/08/2006  01:23 AM    <JUNCTION>     Recent [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Recent]
09/08/2006  01:23 AM    <JUNCTION>     SendTo [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\SendTo]
09/08/2006  01:23 AM    <JUNCTION>     Start Menu [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Start Menu]
09/08/2006  01:23 AM    <JUNCTION>     Templates [C:\Users\Scott\AppData\Roaming\Microsoft\Windows\Templates]
09/08/2006  01:23 AM    <JUNCTION>     Application Data [C:\Users\Scott\AppData\Local]
09/08/2006  01:23 AM    <JUNCTION>     History [C:\Users\Scott\AppData\Local\Microsoft\Windows\History]
09/08/2006  01:23 AM    <JUNCTION>     Temporary Internet Files [C:\Users\Scott\AppData\Local\Microsoft\Windows\Temporary Internet Files]

Notice that I had to use /a because these junctions are HIDDEN as well. But, because they exist, when folks concatenate things after calling "GetSpecialFolder" they'll still get what they need.

I had a little trouble with my upgrade because I ended up with some stuff on my C: and My Documents on my D:, but Vista was still pointing to C:\Users\Scott for My Documents.

I tried to get tricky like this:

C:\Users\Scott>junction "My Documents" "D:\Scott\My Documents"
Junction v1.04 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2005 Mark Russinovich
Systems Internals -
http://www.sysinternals.com
C:\Users\Scott\My Documents: JUNCTION
   Print Name     : C:\Users\Scott\Documents
   Substitute Name: C:\Users\Scott\Documents

But while a cross-drive junction succeeded with Junction.exe, it apparently really didn't:

C:\Users\Scott
>dir *doc* /a
 Volume in drive C is 70 GIGS - SYSTEM
 Volume Serial Number is 88F3-D225
 Directory of C:\Users\Scott
09/08/2006  01:23 AM    <JUNCTION>     My Documents [\??\D:\Scott\My Documents]
               0 File(s)              0 bytes
               1 Dir(s)   6,877,286,400 bytes free

...and...

Vistamydocuments1C:\Users\Scott>dir /a "My Documents"
 Volume in drive C is 70 GIGS - SYSTEM
 Volume Serial Number is 88F3-D225
 Directory of C:\Users\Scott\My Documents
File Not Found

You are supposed to be able to create a "Volume Mount Point" like in *nix where you point a directory at a volume, but that's not exactly what I need here. I'm not sure why it didn't work, because it's supposed to be supported scenario in NTFS.

Well, while I'm not getting the junction to work, I can still move My Documents in the registry by simply right-clicking on the Document folder and moving it with the built-in UI as we've always been able to in Windows XP. It appears that David Mohundro has discovered some of this interesting stuff as well, although I'm not seeing the same behavior as him; my "Documents and Settings" folders are totally gone and emptied, replaced by C:\Users.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 29, 2006 15:12
Wow,

This is truelly a great update.

My co-admin wiped 20 Gigs of data because he forgot we used Junction to get 'that one directory' within the larger collection (such that our users only had to traverse one network path.)

We needed space on the server and he couldn't understand why we had two copies of such large size, wiped one of the directories and whoaaaaa, 20 Gigs x 2 disappeared.

Oh well, find those backups.

As we also admin a number of other Unix boxes, it really would be nice to get a 'link' type clarification with directories.

Thanks for the heads-up.


Sam T.
September 29, 2006 21:25
Cross-drive junctions are my salvation, in a lot of cases. I've inherited a lot of bad build scripts and code with hard-coded paths pointing to c: that I really need to resolve to d:, and cross-drive junctions were a quick fix. I sure hope this isn't permanent.

Someone call Mark Russinovich.
Cam
October 01, 2006 20:40

Have you tried using the new Vista symbolic directory link support available in the command line program "mklink /d". I have successfully used it cross-drive for other directories,though I haven't tested it in your scenario.

--p.
October 04, 2006 11:49
A problem with Volume Mount Points is that security permissions do not inherit from the parent directory of the mount point. While this may seem reasonable from the view of the file system mounting a drive in another drive's subfolder - it is works against my expectations of the way a subfolder should inherit permissions

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.