'Using BATCH file to install software (which I have working) and THEN create a shortcut file

Here is what I have so far:

IF EXIST "C:\Program Files (x86)\Yawcam\Yawcam.exe" GOTO :eof

ELSE

start \\hazel\software$\YawCam\v6.0\yawcam_install.exe /SP- /VERYSILENT

xcopy "\\hazel\software$\YawCam\Doc Cam.lnk" "C:\users\public\desktop\Doc Cam.lnk" /C /Y

:eof

pause

EXIT

Now, it installs properly, but doesn't create the shortcut. I have tried so many different combinations of switches, quotes, and statements. I just can't seem to get it to work. I would very much appreciate any help with this, because I'm sure it is just something I have simply overlooked. Thank you in advance!



Solution 1:[1]

The following rewrite requires to be run As administrator.

If Exist "%ProgramFiles(x86)%\Yawcam\Yawcam.exe" GoTo :EOF

"\\hazel\software$\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT
XCopy "%~dp0Doc Cam.lnk" "%PUBLIC%\Desktop" /C /Y
Pause

Solution 2:[2]

I would write it like this:

pushd "\\hazel\software$" || exit /B 1
if not exist "%ProgramFiles(x86)%\Yawcam\Yawcam.exe" (
    ".\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT
)
copy /Y ".\YawCam\Doc Cam.lnk" "%PUBLIC%\Desktop\Doc Cam.lnk"
popd
exit /B

What I did, and why:

  • added pushd to resolve the UNC path \\hazel\software$ as some commands might have trouble with such; || means to execute next command in case of failure, exit /B 1 exits the batch file if pushd fails, like when the path could not be found; popd at the end restores the previous working directory finally;
  • reversed the if query as you want something to happen in case the condition is not met; this also avoids the need of goto; in addition, never define a label :EOF as this is a reserved name (see this: goto); regard that your if/else syntax is wrong!
  • used environment variables for system paths, like %ProgramFiles(x86)% and %PUBLIC%, because the directory locations may be different on some systems;
  • removed the start command as it is usually not necessary to run external (console) programs; (if it is required for this application for some reason, you might want to change the syntax to: start "" /WAIT ".\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT)
  • replaced xcopy by copy since you are copying a single file only, in order not to having to deal with the F = file, D = directory prompt;
  • added switch /B to exit in order to just terminate the batch file but not the hosting command prompt (cmd) instance;

Solution 3:[3]

I'm not sure if this method is necessarily the best way to go about it, but it got it working for our needs! I appreciate all your guys' help with this! We looked at each comment/answer and went from there. Thank you!

Here's what we did in the end:

IF EXIST "C:\Program Files (x86)\Yawcam\Yawcam.exe" GOTO eof

ELSE

start \\hazel\software$\YawCam\v6.0\yawcam_install.exe /SP- /VERYSILENT

:eof

Echo F|xcopy "\\hazel\software$\YawCam\Doc Cam.lnk" "C:\users\public\desktop\Doc Cam.lnk" /C /Y

EXIT

Hopefully this can help someone trying to do the same in the future!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Compo
Solution 2 aschipfl
Solution 3 Devan Andrew Swope