iconJunction Box

A utility aimed at overcoming some of the problems created by  the 'junctions'  in Windows 7/8/10 user profiles. 

 
An issue often experienced by users of Windows 7-on is that the userdata may prove hard to back up. Whilst the copying of individual files in 'Documents' or Pictures' to another location such as a USB disk is quite straightforward, any attempt to make a backup of the whole profile structure is likely to run-into a situation where either some content is missing from the backup, or the else the copy process gets stuck in an endless loop.

This bulk-copy problem arises due the presence of junctions within the profile structure. More specifically, the endless loop situations stem from the fact that some of these junctions are cyclic, that is, they refer back to a higher-level folder which contains.. the folder which the junction itself is in. 

To mitigate the endless-loop issue, Microsoft gave the junctions special filesystem permissions which hide them from the normal Explorer view, and also prevent entry to them by clicking on them, should they be made visible by changing the Explorer settings. Unfortunately it's a bit of a hack solution, since the only way to produce a backup you can have full confidence in is to back up all files including the hidden ones. Otherwise you may miss stuff like your email. Just slightly important, I would think. Which takes you right back into the endless loop problem.

There are backup programs which work around these issues. Cobian Backup is one which we would strongly recommend. However, the situation occasionally arises where you simply must make a direct copy of your data to another location, including hidden folders. JunctionBox can assist you with this, by temporarily removing the troublesome junctions. 

What is a junction?

A junction is a filesystem object not unlike a folder/directory (in fact it appears to most software that it IS a folder) but which is in reality a link to a folder elsewhere on the disk, or even on another disk.

When used carefully, junctions allow data from other sources to be included-into a folder-structure, such that software need not even be aware that the data is in fact located elsewhere. This can be useful in a number of circumstances. For example, you might have a second disk which is E: and want to make it appear that a folder on it is inside of 'My Documents' -as well as the regular stuff in there. That is a legitimate use of a junction - or in that case a directory symlink might be a better choice. Since the source and target are well separated, there should be no endless-loop issues with that kind of usage.

Why are Windows' own junctions problematic, then?

With the introduction of Windows Vista, Microsoft decided to change the arrangement of folders inside a typical user profile. For example, 'My Documents' became simply 'Documents' and 'My Pictures' which was previously inside of 'My Documents' became a separate folder, 'Pictures' on its own. This created a situation where legacy programs written for Windows XP might not function correctly, so junctions were added to simulate the presence of the previous folder names, as well as the new ones.

The key issue here is that by the very nature of the situation some of these junctions have to refer to locations which include themselves. In other words, they are cyclic junctions. Without special measures, the consequence would be that programs which scan the folder-structure get stuck in an endless loop when they hit these cyclic junctions.

In an attempt to 'fix' this, Microsoft gave the junctions a special permission, that of Deny List Contents to Everyone. The idea here is that software which tries to scan the structure should see the junctions as being empty folders, and ignore them. Unfortunately the fix doesn't always work.

There is a secondary concern here, that a backup of the user's data, even if complete in terms of files, cannot include these special junctions. Because, if it tried to it would become stuck in a loop. So, having a full copy of your data  does not necessarily mean that you could reinstate that data if the original should be lost for some reason.

The cyclic junction userdata issue affects Windows 7 and 8, but is less prevalent in Windows 10 where userdata contains only two relatively unimportant junctions. However, all such OSs have junctions in the system folders as well as in userdata, so in all cases a means of backing-up and/or repairing the junctions is desirable.

What does Junction Box do?

JunctionBox allows you to create a a catalog file of the junctions on your computer. This file has an .ntj extension, and is typically created in the same folder as JunctionBox.exe.

You can do two things with this catalog file:

  • You can use it to selectively remove the junctions from a specific user's data, and then reinstate them after a data copying process has completed.
  • You can use your own catalog or a prebuilt DefaultJunctions file to repair a computer on which the junctions have been damaged in some way, or accidentally deleted.

Installing the program

JunctionBox comes as a zip archive. You can extract the contents with Windows Explorer, or with any number of third-party unzippers, for example 7-zip. You need to extract all of the contents to a suitable folder, running the executable directly from the zip will not work.

The location you extract to must allow running of programs, and saving of data. In most cases a folder created on the Desktop will be OK. The program must be run as an elevated user with full rights, and will ask for elevation (screen dimming) if that is not the case. It is not necessary to restart the computer or use the actual Administrator account, although doing so is never a bad idea for any serious system-changing work.

Aside from the changes to junctions, no alterations are made to system files or the registry. Uninstall is simply a question of deleting the containing folder.

Creating a Backup

Press Backup, and enter a suitable filename and location. Or just accept the suggested name. (The suggested extension is .ntj) By default, backups are saved to the program's own folder, since this is intended to be a portable utility. Depending on the amount of data on your disk and the processing power available, this may typically take several minutes. Once finished you should have a backup file. The structure of this is explained in DefaultJunctions.ntj  -which you can safely examine in Notepad. It is basically a text file.

Backups always include the full set of junctions, the profile selector having no effect on this function.

Restoring Junctions

Firstly select whether you wish to restore the set of junctions for the system-disk, or just those in a specific user-profile. 

You will then be presented with a file selector, from which the appropriate catalog should be selected.
A set of standard junctions is provided is the file DefaultJunctions.ntj, and this may be useful where you need to repair a computer for which no catalog has been made.

The restore process is relatively quick as only a small amount of data need be scanned, just the junctions.

After being restored, the junctions will have their special permissions applied, so that (well, in the hope that) this will prevent endless loops.

At present the software does not provide any way of restoring junctions without also adding these special permissions. If thought necessary this facility could be added.

Deleting Junctions

Select the profile to delete the junctions within, and select Delete from the Junctions menu. Again you will be asked to specify a catalog file. This is NOT so that a backup can be made, and the catalog will not be altered. What happens here is that the catalog is used to identify the junctions to delete.

This approach is seen as being relatively safe, in that junctions will only be deleted which have already been included in the catalog. So, if you didn't backup, then you can only delete the default set of junctions, using DefaultJunctions.ntj. If you want to delete custom junctions which you've added yourself, then you need to backup first. Which, I think, makes sense.

Dependencies

JunctionBox requires SetACL.exe by Helge Klein. This is included in the distribution, and is GPL licensed. The sourcecode is available from setacl.sourceforge.net.

The MKLINK component of cmd.exe is also required for restore operations, which rules-out use on platforms earlier than Vista. That said, earlier platforms such as Windows XP do not normally require a junction manager. Which is a bit like saying if you don't have the plague.. then you don't need an injection. ;-)

Notes

To confuse matters (Yeah, it's a computer..)  there are actually four types of 'link' in existence- junctions, file and directory symlinks, and hardlinks. Version 2 backs up and restores symlinks as well as the regular junctions. There is only one symlink in a standard Windows install, and that is the 'C:\Users\All Users' folder. Unlike the junctions this is not hidden from Explorer since it does not represent an endless-loop risk. In version 1 we left this alone, but for completeness v2 backs it up. For operational reasons v2 does not back up hardlinks. There are currently no hardlinks in any standard Windows install. 

Windows 10 has a different set of junctions from Windows 8, thus you must use the appropriate catalog file. There is only one minor difference between Windows 7 and 8, hence the same catalog file serves for both. Vista, if anyone still has it, can also use the Windows 7/8 file.

Never attempt to delete a junction or symlink using Windows Explorer. You will probably not succeed, but if you DO, this will result in the contents being deleted instead of the junction itself, which could potentially be a disaster.

International Versions of Windows:

The names of system folders differ between languages, therefore a catalog made in one language should not be applied to another. To reduce the risk of accidents of this kind, the catalog-file header carries the locale information. You can edit this manually if you are sure that the file is suitable for your locale. See the comments in DefaultJunctions.ntj for more information.

Presently there is no support for languages which use special character-sets, which includes most Asian languages. As I don't have access to a suitable platform to test such aspects on, feedback or suggestions from users who do would be welcome. Be aware that operation on these language-versions is completely unverified, so please don't do your tests on a production computer!

Making your own DefaultJunctions file:

To make a DefaultJunctions.ntj file, run the backup option on an unmodified copy of the required Windows localization. Edit the file this produces using a text-editor (e.g. Notepad) to remove the useraccount-specific sections. Retain the system-folder sections and the All Users, Public and Default (or language equivalent thereof) profile sections. If necessary, add any more applicable locales to the OSLanguanges value in the General section, separated by commas. Now rename the file to DefaultJunctions.ntj

Download:

Executable and sourcecode are available from the local download link. They are no longer on Sourceforge.

Note that this utility has suffered some false antivirus alerts, notably from Norton and McAfee. From the coder's standpoint there is nothing much that can be done about this, it seems as if some antivirus vendors are nowadays writing code so trigger-happy that it flags ANY program which makes fundamental system-changes (which this has to do, or it would be of no use!) as potential malware. Notably, the better AV products produce no such false-alerts. My advice here is simple: If you want protection which actually works properly, you need to change your antivirus software.

Legal:

As ever, you use this system-level utility entirely at your own risk. Various forms of disaster are not excluded from the list of possible outcomes of its incorrect use. Or, even of its correct use.

This software may be duplicated any number of times, and used in private or commercial IT operations. There is no charge for such usage. We retain the right to charge for technical support work, should this be contactually requested. 

The sourcecode and executables of this software are released under the GNU Public Licence, version 3. Icons and other graphics remain the intellectual property of IWR Consultancy, and may not be used in derivative works without permission.

It is not necessary to supply sourcecode with every downloaded copy, so long as a link to the publisher's website is included in some form or other at the download location.