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.

We have a batch file which creates shortcuts on Windows 2003 machines. The command which we use is something like:

echo copy the shortcut to the server All Users folder for windows 2003...
xcopy "%OutputDir%%LocalOutputDir%\Shortcuts\*.*" "\\%SERVERNAME%\c$\Documents and Settings\All Users\Start Menu\Programs\Startup\*.*"

Now, we have some new Windows 2008 machines also and their path of the Shortcut folder (ALL USERS) is different (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup).

So my question is how do we put an if condition so that if the batch file doesn't find the location of 2003, it saves the shortcut in the location of the 2008 machine...

Thanks!

share|improve this question
add comment

1 Answer

IF <statement>  (
..
..
) ELSE (
...
...
)

....... or separate IF statements without an ELSE in case there is a third path

IF exist "\\%SERVERNAME%\c$\Documents and Settings\" (
...
...
)

IF exist "\\%SERVERNAME%\C:\ProgramData\Microsoft\Windows\Start Menu\" (
...
...
) 

you might want to use/checkout the environment variable "ALLUSERSPROFILE" It gives you access to the following folders automatically:

on XP and 2000> C:\Documents and Settings\All Users
on Vista/Win7/+> C:\ProgramData

if you use the variable instead of the hard coded path, you do not need the IF statement...

xcopy "%OutputDir%%LocalOutputDir%\Shortcuts\*.*" "\\%SERVERNAME%\%ALLUSERSPROFILE%\Start Menu\Programs\Startup\*.*"
share|improve this answer
add comment

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.