1

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!

1
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\*.*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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