I have an app which saves its data on C:\ProgramData
. That means for all users, it uses the same data. I want to achieve a way, so that different users can have their own separate data space. I have used symlink (folder junction) to create it to %userprofile%\Documents\AppFolder
, and the method works fine on my user profile, but when tried with different user the app doesn't run; as it tries to access C:\User\User1\Documents\AppFolder
, which User2 doesn't have access. Any possible workaround, so the different users can link to different symlinks?
Windows – Different symlink for different user on Windows
symbolic-linkwindows
Best Answer
You can use the
subst
command to map a drive letter to your user directory. Drive letters created bysubst
are per-user, so you can create the same mapping as each user and then create a symlink to that drive letter. Or just point the program to the mapped drive via its settings.An example:
A downside of this solution is that mapped drive letters are not persistent, so you have to recreate them every time a user logs in (for example, by putting a shortcut to the
subst
command into%appdata%\Microsoft\Windows\Start Menu\Programs\Startup
. Or you can make a batch file which will runsubst
and then your program.An alternative solution is to run your program in a sandbox (e.g. Sandboxie).This won't work if the program tries to do something low-level (e.g. installing drivers or services). Also you'll have to restore files created by the program from sandbox after each run in you need to use them elsewhere.