Windows

Manually creating junction points in Windows XP

NTFS junction and reparse points can help you find files on a hard drive quickly. Here's how you can manually create NTFS junction points on your Windows XP workstations.

NTFS reparse points (mount points and junction points) can reduce the amount of time and effort you spend navigating your hard disk. The most useful of the reparse points feature are junction points, which allow you to redirect a folder on one hard disk to another folder on the same hard disk or on a secondary hard disk.

When it comes to creating junction points, the only Microsoft utility designed for the task—a command-line tool called Linkd.exe—doesn't even come with the operating system and isn’t very efficient. However, I recently discovered an undocumented method in Windows XP for manually creating junction points without the need for the Linkd.exe utility or any third-party software. This undocumented method simply involves creating a specially configured Desktop.ini text file, a standard shortcut, and a few folder manipulations. Here’s how to create the special Desktop.ini file and how to use it to quickly and easily create junction points.

Caveats

Working with NTFS junction points involves traps that are easy to fall into if you don’t really understand what you’re doing. It’s important to keep in mind that NTFS junction points are designed to work only on local hard disks. They don’t work across a network. In other words, you can’t create a junction point on an NTFS drive that points to a network drive.

Another big trap is that you can indeed delete the folder acting as the junction point from within Windows Explorer or from the command line with the Del command. However, rather than just deleting a junction point, these commands can actually delete the target directory and all subdirectories. So it's extremely important that you use the steps in this article when it's time to remove or change your junction points.

Furthermore, keep in mind that junction points can cause havoc with certain utilities, such as backup programs, that aren’t junction-point aware. You might also notice that the Dir command reports odd free-space statistics on drives that contain folders acting as junction points.

The CurrentWork file-management technique

In a previous article, I showed you how to use reparse points along with the CurrentWork technique. Since this example technique really helps to bring home the goals achieved by using junction points, it's worth taking a moment to briefly recap the CurrentWork file-management technique.

The main advantage of using junction points is to reduce the amount of time and effort you spend navigating your hard disk in both Windows Explorer and in your application's Open and Save As dialog boxes.

Ever since I discovered the benefits of junction points, I’ve kept a folder named CurrentWork in the root directory of my NTFS drive. As I begin each new writing assignment, I create a junction point that redirects the C:\ CurrentWork folder to a folder deeply nested in the folder structure that I use to keep my work organized. For example, the target folder could have the path:

C:\Documents and Settings\Greg Shultz\My Documents\My Work\Freelance\TechRepublic\10-October04\JunctionPoints

As I finish an assignment, I remove that junction point and create a new one for the next assignment. Of course, this means that the target folder is always changing as I move from assignment to assignment. However, once I create the new junction point, the only folder name I have to navigate to when opening, saving, or copying files related to the assignment is the C:\ CurrentWork folder. This has saved me an immeasurable amount of time and frustration.

Once you learn how easy it is to create your own junction points, you can apply this example to the way you work. Chances are good that you, too, will reap the benefits once you get into the habit.

Preparation

Now that you have an idea of how the CurrentWork file-management technique works, we’ll use it as an example as we move forward. To get started, we need to do some prep work that involves creating a CurrentWork folder, the Desktop.ini file, and two special helper files.

To begin, launch Windows Explorer and create a new folder in the root directory called CurrentWork. Next, launch Notepad and type the following text:

[.ShellClassInfo]CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}

Save the file in the CurrentWork folder as Desktop.ini. By default, Notepad will append the .txt extension unless you enclose the filename in double quotes in the Save As dialog box.

The Desktop.ini file is a standard text file used to customize the appearance and behavior of the folder that it contains. In this case, the commands in Desktop.ini allow the folder to be configured as a junction point. Let’s take a closer look.

The [.ShellClassInfo] line is a section heading indicating that the entries and assigned values that fall under the heading will, in this case, customize the folder's behavior. The CLSID2 entry is assigned the value {0AFACED1-E828-11D1-9187-B532F1E9575D}, which points to a registry key that identifies a special folder shortcut named Target.

While Notepad is still open, press [Ctrl]N to open a new document. Then, type the following command:

Attrib +s C:\CurrentWork /s /d

Save the file in the root folder as EnableSys.bat. Replace the plus sign with a minus sign so that the command looks like this:

Attrib -s C:\CurrentWork /s /d

Save the file in the root folder as DisableSys.bat. As you can see, both of these batch files run the DOS command Attrib, which allows you to set file and folder attributes. We have to resort to the Attrib command because Windows Explorer allows you to set only the Read-only and Hidden attributes.

In the case of EnableSys.bat, the Attrib command is used to set the system attribute on the CurrentWork folder. In the case of DisableSys.bat, the Attrib command is used to remove the system attribute on the CurrentWork folder.

Creating a junction point

Now that you’ve created and saved the Desktop.ini file in the CurrentWork folder and the EnableSys.bat and DisableSys.bat files in the root directory, you’re ready to create your junction point. The first step is to create a shortcut to the folder you want the junction point to refer to.

The easiest way to create this shortcut is to open the CurrentWork folder, pull down the File menu, and select the New | Shortcut command. When you see the Create Shortcut Wizard, click the Browse button and use the Browse For Folder tool to locate the folder, as shown in Figure A.

Figure A

junction-points-5388706a.gif

The Create Shortcut Wizard’s Browse For Folder tool makes it easy to create a shortcut to a folder that is deeply nested in the folder structure.

After you click OK and Next, the wizard will prompt you to provide a name for the shortcut. Type Target in the text box, as shown in Figure B, then click Finish. (As you’ll remember, the CLSID2 entry in the Desktop.ini file points to a key in the registry that identifies a special folder shortcut named Target.)

Figure B

junction-points-5388706b.gif

In order for the manual junction point technique to work, you must name the shortcut Target.

Navigate to the root directory and double-click the EnableSys.bat file. You’ll momentarily see a Command Prompt window. When the window disappears, open the CurrentWork folder and you’ll find that you now have easy access to your Target folder. (Keep in mind that it may take a couple of seconds for the junction point to take effect.) As Figure C shows, I now have access to C:\Documents and Settings\Greg Shultz\My Documents\My Work\Freelance\TechRepublic\10-October04\JunctionPoints.

Figure C

junction-points-5388706c.gif

As you can see in the Address text box, the CurrentWork folder now provides easy access to the deeply nested Target folder.

Changing the junction point

When it’s time to work in another folder, you’ll need to change the junction point. First, access the root directory, double-click the DisableSys.bat file, and open the CurrentWork folder. You’ll now find the Desktop.ini file and your Target shortcut file. You can either edit the Target string of the Target shortcut file, as shown in Figure D, or you can delete the Target shortcut file, launch the Create Shortcut Wizard, and create a new one.

Figure D

junction-points-5388706d.gif

One way to change the junction point is to simply edit the Target string in the shortcut properties box.

Straight to the point

Using junction points can save you time and effort by simplifying the process of navigating your hard disk in both Windows Explorer and in your application's Open and Save As dialog boxes. Creating junction points manually is easy once you know how, and it spares you from having to install yet another utility in your already overburdened operating system.

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

6 comments
kf
kf

Can you describe how this is different (in the way that you indicate you are using it) from using a regular "Shortcut.lnk" link? Of course, Junction/Reparse-Points are much different from "Shortcut.lnk" links. For example, suppose that you create a Junction Point at "C:\CurrentWork", pointing to "D:\Freelance\TechRepublic\June 03\Reparse Points". Then, from Windows Explorer, if you navigate to "C:\CurrentWork", you will see the files and folders located at "D:\Freelance\TechRepublic\June 03\Reparse Points". The same will be the case if you navigate to "C:\CurrentWork" from any "Open - "Save" - "Save-As" dialog. Also, from a Command-Prompt window, if you change to drive "C:\", then you could do CD "CurrentWork" and again, you would see the files and folders located at "D:\Freelance\TechRepublic\June 03\Reparse Points". Alternately, you could create a "Shortcut.lnk", named for example: "C:\CurrentWork(.lnk)" pointing to "D:\Freelance\TechRepublic\June 03\Reparse Points". Then, from Windows Explorer, if you navigate to "C:\CurrentWork(.lnk)", you will see the files and folders located at "D:\Freelance\TechRepublic\June 03\Reparse Points". Again, the same will be the case if you navigate to "C:\CurrentWork" from any "Open - "Save" - "Save-As" dialog. The difference here is that you cannot "CD" to the target of a "Shortcut.lnk" from a Command-Prompt window. It seems to me, that either way you do it, Junction Points, or "Shortcut.lnk", will serve as a quick (one click) way to navigate to a folder located deep within the directory structure of a drive. So, what do you see as the advantage of using Junction/Reparse Points (or your "desktop.ini" trick), compared to the simpler to create/manage/edit Shortcut.lnk ? Thanks, Kevin

BigueNique
BigueNique

Thanks, whatever you call that trick, junction or alias, it's pretty easy and useful!

nullnullnull
nullnullnull

Hello there, this is no a junction point is a link embebed in a folder, a junction point is a special object in the NTFS structure, there is the next type of objects in a NTFS Structure. Files, Folders AND junction points.

david4356
david4356

This isn't documented for a reason. This creates a pseudo-junction that only works in Explorer and the Shell. It does not work internally for either high or low level I/O. When you follow one of these pseudo-junctions, you actually get switched to the target location. You can create true Junction Points, which are actually retained in the file or folder address and which work for any I/O, by using the junction.exe program from the SysInternals group at Microsoft. I use a true junction point on two computers to map the same address to two different places in the file system. I do this so I can use the same configuration files on both computers so I can synchronize edits (I do development on both computers). On one computer, the junction point C:\L maps to C:\ and on the other computer, C:\L maps to D:\. Neither pseudo-junctions, described here, nor the subst command (which maps drive letters) meet this kind of need, but true junctions work perfectly. David Spector Springtime Software

commenting
commenting

A reparse point is an actual NTFS entry on the filesystem that points to another entry on a file system (residing within the same physical machine). This is completely invisable to whatever application tries to read the contents of the "alias" folder (except those looking explicitly for the reparse signature). The instructions you've described, on the other hand, are for creating Explorer-based folder aliases. From a user standpoint, the difference is that these aliases only work when browsing the folder structure using an explorer-based browsing mechanism. Programs that instead read the folder contents using a filesystem API will instead simply find a directory with a desktop.ini and target.lnk file in it. The differences are described in more detail at WinbolicLink's site: http://www.pearlmagik.com/winbolic/