# Windows XP/7 copy command line involving junction

I have a batch script which needs to work with Windows XP (for the time being) and Windows 7. The script also copies a link to the Windows Desktop.

copy /Y path\to\the\link.lnk %ALLUSERSPROFILE%\Desktop\link.lnk


This works on Windows XP but not on Windows 7. There %ALLUSERSPROFILE%\Desktop is a junction and even with the admin account I get "Access denied" when executing the command. I thought junctions were there to forward me to the correct location (%PUBLIC%\Desktop in this case), but it seems it does not work.

Any way I can make a XP/7 compatible command line?

-

I use this on both Windows XP and Windows 7 to set a variable for which path to use. In this code AUDESKTOP is set depending on which OS it is being run on.

IF DEFINED PUBLIC (SET AUDESKTOP=%PUBLIC%\Desktop) ELSE (SET AUDESKTOP=%ALLUSERSPROFILE%\Desktop)


Then call the variable in the command line like this;

As far as why it errors in Windows 7, make sure there are quotes around paths. If it still doesn't work, try to run as administrator.