Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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;

copy /Y "path\to\the\link.lnk" "%AUDESKTOP%\link.lnk"

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.

share|improve this answer
    
thank you, with this I can work! –  Sebastian Elsner Jan 18 '13 at 14:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.