Windows – Directory Junction keeps being deleted

directory-junctionfirefoxsymbolic-linkwindowswindows 10

I have upgraded from Windows 7 to 10 Professional on an SSD and I have created Directory Junctions, using command line mklink /J, for folders like Games, Mozilla Profiles, etc. pointing to a HDD directory. All of the junctions work well except for Mozilla Firefox profile which is linked like this:

Junction created for C:\Users\[USERNAME]\AppData\Roaming\Mozilla <<===>> H:\Users\[USERNAME]\AppData\Roaming\Mozilla

Although this junction works fine when created, at random intervals it is being deleted. Either after computer sleep the junction is missing, or after a restart, or anytime while using the computer. It doesn't happen every time I restart the computer or put it to sleep, etc. It seems to be completely random.

I tried Directory Symbolic link as well (mklink /D), but the same happens. Interestingly enough, I don't face any problems with the other junctions on the same volume H:

There are no issues with NTFS permissions and volume H: is a fixed HDD (not a removable one).

Any ideas what is causing this?

Best Answer

PortableApps is causing the deletion of the junction but the problem lies within Windows rmdir command. According to this thread on PortableApps forum, all applications packaged in PortableApps format, rely on rmdir to remove any leftover folders that might be created by the portable application. rmdir can remove an empty folder, will provide an error if the folder is not empty, but when used against a junction it just deletes the junction itself.

Portable Applications that use the AppData\Roaming\Mozilla folder, remove the junction when closed. Such portable applications include Seamonkey, Firefox Developer Edition, Firefox, etc.

Currently there seems to be no solution or workaround to this problem from the PortableApps side. There is though one thing that can be done to prevent the junction from being deleted. Instead of creating a junction (mklink /j) we can create a symbolic link (mklink /d) and then edit NTFS permissions on the symlink, adding Everyone Deny Full. I came up with this solution after reading this SU thread.

Related Question