Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...


share|improve this question
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .