Showing results for 
Search instead for 
Do you mean 
The blueprint for the future of work
Register today!
Attend BoxWorks
Desktop, meet cloud.
Box Drive is the easiest and fastest way to connect to the cloud — without changing the way you work.
View resources

Redirect My Documents Folder to Automatically Be Box Sync Default Folder Location

by on ‎08-15-2016 12:03 PM - edited on ‎06-29-2017 10:09 AM by (11,305 Views)
IT Administrators may want to redirect users' My Documents folders to Box Sync. This type of configuration would allow an organization's users to use their My Documents folder as they're accustomed to, while providing added benefits of having those files backed up to the user's Box account. This is also convenient for certain applications that default to save documents to My Documents.
 

Disclaimer: Please note that the configurations identified in this document are not officially supported by Box and any configuration changes performed by users or organizations are at your own risk. As these configurations reference changes made to individual machines, Box User Services is not able to provide support and assistance in trouble shooting any issues encountered.

 
This guide will walk through two ways an administrator can create an end user-initiated utility to assist in this type of folder redirection.
 

Method 1: Utilizing Microsoft APIs

Method 2: Utilizing Changes to End Users' Registries

 

Note: Both of these options require that an end user has successfully logged in to Box Sync and that a Box Sync folder has been successfully created on their machine. It is not possible to provide redirection of the Box Sync folder before it has been created through a successful authentication.

 

Microsoft APIs  

Use of Microsoft APIs allows for a more streamlined solution and does not require end users to restart their machines for the changes to take effect. The information referenced within this section can be written in any language that can access COM APIs (e.g., C, C++, C#, Python, Perl).
 
Refer to the following link for Microsoft's information on the Windows Shell: https://msdn.microsoft.com/en-us/library/windows/desktop/ff521731(v=vs.85).aspx
 
The following flags are recommended for use:
 

Flag

Description

KF_REDIRECT_COPY_CONTENTS This copies the existing contents (both the files and subfolders) of the known folder to the redirected folder location.
KF_REDIRECT_DEL_SOURCE_CONTENTS This deletes the contents of the source folder after they have been copied to the redirected folder.
KF_REDIRECT_UNPIN This unpins the source folder.
KF_REDIRECT_PIN

This pins the target folder.

 

 Example Code (written in C)

 

       // Create the KnownFolderManager object

   IKnownFolderManager *folderManager = 0;
   CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_ALL,
       IID_IKnownFolderManager, (void **)&folderManager);

   // Perform the redirection
   LPWSTR error;
   folderManager->Redirect(FOLDERID_Documents, NULL,
       KF_REDIRECT_COPY_CONTENTS |
       KF_REDIRECT_DEL_SOURCE_CONTENTS |
       KF_REDIRECT_UNPIN | KF_REDIRECT_PIN,
   boxSyncDocumentsPath, 0, NULL, &error);

 

Registry Changes

Use of registry changes is a secondary approach that can be used by administrators to redirect the user's Desktop. Documents, Favorites, Pictures, Music, Video, etc. folders to point to folders inside the Box Sync folder. Please note that this option requires a restart to the users' machines before the change takes effect, and that any movement of files may cause document paths to change. As a result, users may experience unintended impacts (e.g., accessing an old file through "Recent Files" may fail).
 
With this redirection in place, applications will, by default, offer to save files in these folders, and saved documents will automatically be uploaded to Box.
 
Configuration changes should be made by going to the registry at:
  • HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

The registry can be changed through standard registry APIs. For additional reference material, refer to the following page: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724871(v=vs.85).aspx

 
To migrate all content within a user's default My Documents folder, the following folders will need to be created within the user's Box Sync folder:
  • Box Sync\FileSync\Desktop
  • Box Sync\FileSync\Documents
  • Box Sync\FileSync\Favorites
  • Box Sync\FileSync\Pictures
  • Box Sync\FileSync\Music
  • Box Sync\FileSync\Video
Below are the configuration changes that should be made: 
 

Registry Value (Example)

Old Value (Example)

New Value (Example)

Desktop %USERPROFILE%\Desktop %USERPROFILE%\Box Sync\FileSync\Desktop
Personal %USERPROFILE%\Documents %USERPROFILE%\Box Sync\FileSync\Documents
Favorites %USERPROFILE%\Favorites %USERPROFILE%\Box Sync\FileSync\Favorites
Pictures %USERPROFILE%\Pictures  %USERPROFILE%\Box Sync\FileSync\Pictures
Music %USERPROFILE%\Music %USERPROFILE%\Box Sync\FileSync\Music
Video %USERPROFILE%\Video %USERPROFILE%\Box Sync\FileSync\Video
Note: On Windows 10, it is a known issue that the 'Quick Access' links do not work in this configuration.
 

Example Code

The following is an example of a script that can be used as a starting place for your customized script: https://gist.github.com/anonymous/53b81a190d0e24e93cbb00dd48ab5cc7
 
______________________
 

Disclaimer

The configurations identified in this document are not officially supported by Box and any configuration changes performed by users or organizations are at your own risk. As these configurations reference changes made to individual machines, Box User Services is not able to provide support and assistance in trouble shooting any issues encountered.