3

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!

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 2
    If you run each command directly (not in a batch file and without the `start`), does it work? – Eldad Assis Feb 14 '17 at 19:36
  • 1
    Copying to `"C:\users\public\desktop\"` folder requires elevation. – JosefZ Feb 14 '17 at 20:30
  • If you copy a link from somewhere it will still point to somewhere(else) and not to your newly installed software. You wil need to (re-)create the link with proper paramters. You'll need js-/vbscript/PowerShell/.inf or 3rd party apps to do this. [A quick look around will show you enaugh samples](http://stackoverflow.com/search?q=batch+create+shortcut) –  Feb 14 '17 at 22:13
  • The first line is not good. You assume the standard program files folder for 32-bit applications is always `C:\Program Files (x86)`. But this assumption might be wrong. The drive can be different and also the folder name can be different. 64-bit Windows defines the environment variable `ProgramFiles(x86)` with path to standard program files folder for 32-bit applications on 64-bit Windows. You should make use of it with `IF EXIST "%ProgramFiles(x86)%\Yawcam\Yawcam.exe" GOTO :eof`. – Mofi Feb 15 '17 at 07:05
  • It is also not good to define a label `eof` written in lower case as this might result in misleads on using in batch file also `goto :EOF`. `EOF` in upper case is a predefined label (with command extensions enabled as by default) for exiting batch execution. It would be better to replace in your batch file `eof` for example by `EndBatch`. Also use `EXIT` should be replaced by `EXIT /B` which is exactly the same as `goto :EOF`. `EXIT` without option `/B` always exits entire command process making it not possible to debug a batch file with starting it from within a command prompt window. – Mofi Feb 15 '17 at 07:11
  • 2
    The `ELSE` on second line must be removed. Executing `if /?` in a command prompt window explains how to use an `IF ... ELSE` in correct syntax like [this answer](http://stackoverflow.com/a/34118487/3074564) with more examples for correct syntax. – Mofi Feb 15 '17 at 07:15

3 Answers3

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
Compo
  • 36,585
  • 5
  • 27
  • 39
1

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;
aschipfl
  • 33,626
  • 12
  • 54
  • 99
0

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!

  • 1
    This is still the wrong `if`/`else` syntax! Type `if /?` into a command prompt window and read the help text! – aschipfl Mar 12 '17 at 22:52