Derek Slager

  • Saturday, March 24, 2007

    Emulating Vista's User Directory Structure on XP

    Perhaps the best new "feature" of Windows Vista is the Unix-inspired re-organization of user home directories. That is, instead of placing user-specific files under the abhorrent Documents and Settings directory, each user's folder resides under the command-line-friendly Users directory in the root system drive. Even better, your music is no longer considered a document. It's hard to argue against the fact that C:\Users\Derek\Music is cleaner than C:\Documents and Settings\Derek\My Documents\My Music (or in some cases, the 8.3 friendly C:\DOCUME~1\Derek\MYDOCU~1\MYMUSI~1, ack!).

    I use Vista on a couple of my computers, and I've grown to appreciate the new folder structure. Gone are the days of hacking together your own home directory structures just to try and cope with the unfriendly madness (who hasn't created a folder or two under C:\ just to make them typable?). Unfortunately, I still use several machines running XP, so it's hard to rely on this sane structure -- leading to grotesque hacks such as functions called ghetto-dosify in my .emacs file (I wish I were kidding).

    There are some additional advantages to utilizing the built-in home directory structure rather than creating your own. For example, the Run dialog resolves path reference relative to your home directory. So, if you type Start -> Run -> ., your home directory will open. Sub-folders can be accessed just as easily -- typing Start -> Run -> dev\blog opens my blog source tree. Also, many tools (backup, indexing, etc.) will only consider content in your actual profile directory (the one that Windows knows about).

    Another nice benefit is that the compact path structure is Cygwin-friendly, so you can safely set your HOME environment variable (also used by Emacs, of course). Thus, ~/Desktop in Cygwin matches ~\Desktop in Powershell. I keep my HOME directory synced across many machines (Vista, XP, and Linux) using Subversion, and it's nice being able to keep everything in the same place.

    Fortunately, we can make some relatively simple tweaks to our XP systems to make the structure more closely resemble that of our Vista and Unix friends.

    Junction, Junction, What's your Function?

    Chances are you've been running your operating system for a while, and you've got a bunch of clutter under your Documents and Settings folder. More importantly, you probably have a bunch of applications with stored absolute paths under that folder, not to mention all of those common dialog pointers. So obviously, just renaming the Documents and Settings folder is going to cause more problems than it'll solve.

    If XP had symlinks (another feature added in Vista), of course, we'd have an easy solution. We could simply type ln -s DOCUME~1 Users, and we'd be off to a good start. We could update environment variables to use our new path structure, and we wouldn't break the old path references. Fortunately, XP does support directory symlinks ... well, sort of. XP's default file system, NTFS, supports something called a "junction point". For our needs, it'll do.

    While junctions are supported by NTFS, there is no built-in tool for creating them. Enter Junction, a simple command line tool for creating (and viewing targets of) NTFS junction points. With the tool located in your PATH, run the following command sequence to create the link:

    C:\Documents and Settings\Derek>cd \
    C:\>junction Users "Documents and Settings"
    
    Junction v1.04 - Windows junction creator and reparse point viewer
    Copyright (C) 2000-2005 Mark Russinovich
    Systems Internals - http://www.sysinternals.com
    
    Created: C:\Users
    Targetted at: C:\Documents and Settings

    Special Folders

    At this point, we can access our home directory under the Users path, but unfortunately Windows has no idea that we've actually intended to change our home directory. For example, starting a fresh command line session stills shows that old, annoying Documents and Settings path.

    To fix this, we need to dig into the registry. Under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList, there should be a number of keys in the form S-x-x-xx-.... Browse through the keys until you find the one with a ProfileImagePath value ending with your user name (e.g. %SystemDrive%\Documents and Settings\Derek). Change this value to use the new path (e.g. %SystemDrive%\Users\Derek). You will need to restart Windows for it to pick up the change.

    Setting the Profile Directory in the Registry

    After rebooting, you should default to the new Users path when starting a fresh console session. And because it's actually a junction point, all of your existing files should be right there with you. This is a nice start, but there are still some annoyances: My Documents should be Documents, My Music (and its similarly named friends) should also drop the silly "My" prefix, and ascend one directory (unless you think music is a document, of course).

    Again, junction points are exactly what we need. Use the following command sequence to set them up:

    C:\Users\Derek>junction Documents "My Documents"
    ...
    C:\Users\Derek>for %f in (Music Pictures Videos) do junction %f "My Documents\My
     %f"
    ...

    You might also want to hide the My Documents folder, so you don't see two references to the same folder when browsing your home directory. You could just make it hidden, but if you're like me you have hidden folder display enabled. In this case, we just need to make it hidden and give it the system attribute using the following command: attrib +S +H "My Documents".

    Our paths are now much prettier, but we do get stuck with the ugly default folder icon. Fortunately, you can right click on the folder whose icon you wish to update, click Properties, and change the icon in the Customize tab (you must do this before the next step, where they are assigned as special folders). I use the normal icons in shell32.dll for Documents and the like. For my root home directory (Derek), I use user-home.ico (attached to this post) from the Tango Desktop Project. The icon was conveniently translated to ICO format by Ben Brown. You might receive a warning about "enabling task folders", this is safe to ignore.

    As with the Users junction point, we need to tell Windows about our new paths. For this, we'll use a Microsoft tool called Tweak UI. Install the tool, start it (Start -> Run -> tweakui), and select the Special Folders item under My Computer in the tree control. Here you can select each path for which we created a junction, and assign the new path.

    Tweak UI Special Folder Customization

    Common Dialogs

    We've solved our ugly path problem, but overall usability still leaves something to be desired. For example, our common dialogs all have direct pointers to our Documents folder, but it's still rather painful to get to our root home directory to, say, open a music file.

    Fortunately, Tweak UI comes in handy here as well. Under Common Dialogs, select Places Bar, and choose Custom Places Bar. Here, you can define up to five paths that you will have easy access to using the common file dialog used by most Windows applications.

    Tweak UI Places Customization

    Here's the new dialog in action:

    Customized Common File Dialog

    Another nice convenience is having a home directory link in your start menu, as below (simply drag the link there to create the shortcut):

    Customized Start Menu

    Attachments

    • user-home.ico
    13 CommentsPosted at 3:03 AM to Categories: Windows

About

I'm a programmer at Appature, a Seattle-area startup building marketing-focused CRM tools.

Email Me

Recent

  • DVCS Myths
  • A DVCS Story
  • BCrypt.net - Strong Password Hashing for .NET and Mono
  • A Better .NET Regular Expression Tester
  • Emulating Vista's User Directory Structure on XP
  • Screencast: Formatting a CSS File with Emacs
  • Emacs Hack #3: Compile Emacs from CVS on Windows
  • Emacs Hack #2: Manage Emacs Instances with gnuserv
  • Emacs Hack #1: Install Emacs on Windows
  • The Case for Emacs

Categories

  • .NET
  • Baseball
  • C#
  • DVCS
  • Emacs
  • LINQ
  • Security
  • Windows
© Copyright 2008 Derek Slager