Managing Folder Redirection using Junctions in Windows

In many cases with x64 bit platforms, administrators requires to redirect a folder location to some another location. This specifically comes in when there is a system wide folder that needs to be customized per user in which case, you require to redirect the default system wide folder location to point to a per user location.

 

Creating and using and deleting the folder junction using linkd:

C:Test>dir
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:Test

02/03/2012  10:35 AM    <DIR>          .
02/03/2012  10:35 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  81,181,417,472 bytes free

C:Test>linkd C:TestRedirect-to-MyFolder C:MyFolder
Link created at: C:TestRedirect-to-MyFolder

C:Test>linkd C:TestRedirect-to-MyFolder
Source  C:TestRedirect-to-MyFolder is linked to C:MyFolder

C:Test>dir
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:Test

02/03/2012  10:38 AM    <DIR>          .
02/03/2012  10:38 AM    <DIR>          ..
02/03/2012  10:38 AM   
<JUNCTION>     Redirect-to-MyFolder [C:MyFolder]
               0 File(s)              0 bytes
               3 Dir(s)  81,143,132,160 bytes free

C:Test>dir C:TestRedirect-to-MyFolder
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:TestRedirect-to-MyFolder

01/17/2012  01:10 PM    <DIR>          .
01/17/2012  01:10 PM    <DIR>          ..
01/17/2012  01:09 PM                 7 Test1.txt
01/17/2012  01:09 PM                 7 Test2.txt
01/17/2012  01:10 PM                15 Test3.txt
               3 File(s)             29 bytes
               2 Dir(s)  81,143,132,160 bytes free

C:Test>dir C:MyFolder
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:MyFolder

01/17/2012  01:10 PM    <DIR>          .
01/17/2012  01:10 PM    <DIR>          ..
01/17/2012  01:09 PM                 7 Test1.txt
01/17/2012  01:09 PM                 7 Test2.txt
01/17/2012  01:10 PM                15 Test3.txt
               3 File(s)             29 bytes
               2 Dir(s)  81,143,132,160 bytes free

C:Test>linkd C:TestRedirect-to-MyFolder /d
The delete operation succeeded.

C:Test>dir
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:Test

02/03/2012  10:45 AM    <DIR>          .
02/03/2012  10:45 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  81,143,078,912 bytes free

C:Test>dir C:MyFolder
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:MyFolder

01/17/2012 01:10 PM <DIR> .
01/17/2012 01:10 PM <DIR> ..
01/17/2012 01:09 PM 7 Test1.txt
01/17/2012 01:09 PM 7 Test2.txt
01/17/2012 01:10 PM 15 Test3.txt
3 File(s) 29 bytes
2 Dir(s) 81,143,132,160 bytes free

C:Test>

Modifying existing junction to connect to the different folder:

C:Test>linkd C:TestFolder-Junction "C:Program Files"
Link created at: C:TestFolder-Junction

C:Test>dir C:TestFolder-Junctionmozilla*
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:TestFolder-Junction

File Not Found

C:Test>linkd C:TestFolder-Junction "C:Program Files (x86)"
Link created at: C:TestFolder-Junction

C:Test>dir C:TestFolder-Junctionmozilla*
Volume in drive C has no label.
Volume Serial Number is CC0C-B792

Directory of C:TestFolder-Junction

12/20/2011  08:54 AM    <DIR> 
         Mozilla Firefox
               0 File(s)              0 bytes
               1 Dir(s)  81,147,301,888 bytes free

C:Test>

 

 

Junctions Work Across Users:

User1: Modifies the junction to point to a different folder:

C:>linkd C:TestFolder-Junction
Source  C:TestFolder-Junction is linked to
C:Program Files (x86)

C:>linkd C:TestFolder-Junction "C:Program Files"
Link created at: C:TestFolder-Junction

C:>

User2: Junction point for user2 as well redirects to the newly redirected folder by user1

C:Test>linkd C:TestFolder-Junction
Source  C:TestFolder-Junction is linked to
C:Program Files (x86)

C:Test>linkd C:TestFolder-Junction
Source  C:TestFolder-Junction is linked to
C:Program Files

C:Test>

Making Junctions Redirect to User Specific Location Per User:

 

Say you want to redirect a junction to user temp folder, junctions don’t help redirecting locations per user rather they operate across all users that is system wide.  In order to make junctions redirect to user specific locations, one has to map a user specific location to a static path something link subst. Such that the drive redirect to user specific locations.

User: TestUser1

C:>whoami
TestUser1

C:>echo %USERPROFILE%
C:UsersTestUser1

C:>subst R: %USERPROFILE%

C:>dir R: | wc -l
18

C:>linkd C:TestFolder-Junction R:
Link created at: C:TestFolder-Junction

 

C:>dir C:TestFolder-Junction  | wc -l
18

C:>

User: TestUser1

C:>whoami
TestUser2

C:>echo %USERPROFILE%
C:UsersTestUser2

C:>subst R: %USERPROFILE%

C:>dir R: | wc -l
26

C:>linkd C:TestFolder-Junction
Source C:TestFolder-Junction is linked to
R:

C:>dir C:TestFolder-Junction  | wc -l
26

C:>

Leave a Reply

Your email address will not be published. Required fields are marked *