mklink and environment variables
Hi all,
I have a question about symbolic links created with mklink and environment variables in a Windows Server 2008 R2 system.
I have a directory called Connections which is located in the roaming user directory, namely C:\Users\<username>\AppData\Roaming (which correspondes to %APPDATA%).
I have another directory, called C:\MyApplication\Configuration which is accessed by several users.
Now, for several reasons, I need to create a symbolic link in C:\MyApplication\Configuration pointing to C:\Users\<username>\AppData\Roaming\Connections, i.e., the Connections directory belonging to the current logged on user. I tried the following
command being logged on as user "misterx":
mklink /d symlink %APPDATA%\Connections
But, as expected, the symbolic link created points to C:\Users\misterx\AppData\Roaming\Connections, no matter which user is logged on.
So, my question is: is it possible to create a symbolic link pointing to a path containing the %APPDATA% variable? Which could be read as: is it possible to avoid variable expansion when creating a symbolic link?
Thanks in advance.
Bye,
Mauro.
August 30th, 2011 6:23am
Hi,
I have test the issue on my end, same result. By default, to run the mklink, we need to run CMD as administrator first. Then, I run “mklink /d \test %appdata%\Microsoft”,
we can see that “symbolic link created for \test <<===>> C:\Users\administrator\AppData\Roaming\Microsoft”. Go to C:\ drive, we can see the test, its target is “C:\Users\administrator\AppData\Roaming\Microsoft”,
of cause, normal domain user will not have permission to access this shortcut. If you need to create symbolic link for user like U1, you need to run “mklink /d \test1 C:\Users\U1\AppData\Roaming\Microsoft” after launching CMD as administrator.
Thanks.
NinaPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2011 4:36am
Thanks for the answer.
Indeed, my goal is to create the symbolic link once (as an admin user), containing the %APPDATA% as the target folder, so that each user accessing the symbolic link is directed to his personal folder. Kind of a "dynamic symbolic link". In few words: one
symbolic link, many different targets.
I start thinking it is not possible :-(
September 2nd, 2011 5:47am
Hi,
As far as I know, it is impossible. Sorry for the inconvenience.
Thanks.
NinaPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
September 6th, 2011 12:22am
Hi all,
I have a question about symbolic links created with mklink and environment variables in a Windows Server 2008 R2 system.
I have a directory called Connections which is located in the roaming user directory, namely C:\Users\<username>\AppData\Roaming (which correspondes to %APPDATA%).
I have another directory, called C:\MyApplication\Configuration which is accessed by several users.
Now, for several reasons, I need to create a symbolic link in C:\MyApplication\Configuration pointing to C:\Users\<username>\AppData\Roaming\Connections, i.e., the Connections directory belonging to the current logged on user. I tried the following
command being logged on as user "misterx":
mklink /d symlink %APPDATA%\Connections
But, as expected, the symbolic link created points to C:\Users\misterx\AppData\Roaming\Connections, no matter which user is logged on.
So, my question is: is it possible to create a symbolic link pointing to a path containing the %APPDATA% variable? Which could be read as: is it possible to avoid variable expansion when creating a symbolic link?
Thanks in advance.
Bye,
Mauro.
Using an environment string to create a "dynamic" link isn't supported by the underlying filesystem functions, on the other hand, a possible workaround to achieve a similar result could be creating a logon script on the system and invoking mklink inside
the script; basically the script code should invoke mklink a first time to delete whatever previously existing link and then invoke it a second time to recreate the link using the desired environment variable - notice though that such an approach will only
work if one user at a time logs onto the machine otherwise a second user logging on (while the first one is still logged on) would delete/redirect the link so causing troubles
September 6th, 2011 3:09am
Thanks ObiWan,
indeed I have more users connected at the same time.
So I think we agreed my goal is now impossible to reach.
Thanks everybody.
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2011 11:30am
Thanks ObiWan,
indeed I have more users connected at the same time.
So I think we agreed my goal is now impossible to reach.
Thanks everybody.
You're welcome; as for your goal... did you consider using "folder redirection" instead of playing with "mklink" ? I'm referring to
this feature which, if properly configured, may solve your issue
September 9th, 2011 11:34am
I ran into kind of the same issue. I need to create a symbolic link to folder, but the folder needed to be different for each user that was logged. I gave up too. Ran into this page was while googling it.
While it is true that you cannot create a symbolic link using a system variable. You can work around it by creating a symbolic link to a network drive.
A simple example would be.
You have share folder called Configs. In this folder you have a folder for each users.
You have a log on script like:
net use z: /delete
net use z: \\server\Configs\%username%
Create a symolic directory link:
cd \
mklink /d Configuration z:\
Now as each user logs on they will have their own Configuration folder on the root of the drive.
I posted this because I couldn't find a dang answer or work around!! Pretty slick I know.. ;-) Idea just came to me driving down the road one day.
Free Windows Admin Tool Kit Click here and download it now
July 11th, 2012 4:38pm