Reputation: 105
I have a small network with 3 groups of workstations. I use a batch file to push 3rd party updates by group (workstation names in text files by group) that I'm trying to recycle for this. I want to install an application, but only if Outlook 2016 is installed. Reading the help file for "if", I thought I could just add an "if exist 'filename' goto end", but it's not working. It seems to completely skip the "if exist" line and install the app with or without Outlook 2016. What am I missing?
@ECHO OFF
SET /P GroupName=
FOR /F %%A IN (\\server\share\admin\workingfolder\update\groups\%groupname%.txt) DO (
IF EXIST "\\%%A\c$\program files (x86)\Microsoft Office\Office16\Outlook.exe" GOTO END
xcopy /e /q "\\server\share\admin\software\application" "\\%%A\c$\temp\application\"
psexec cmd "\\%%A\temp\application\application.msi"
rmdir /s /q "\\%%A\c$\temp\application\"
)
exit
:END
ECHO "Outlook 2016 was not detected, application not installed > "\\server\share\admin\software\application\install logs\%%a.txt"
exit
Upvotes: 1
Views: 667
Reputation: 82307
You have two issues:
1) Your description doesn't fits to your code. Your code will install only when outlook.exe doesn't exist.
2) GOTO
will break any block, also a FOR block
Solution: Don't use GOTO
in blocks.
FOR /F %%A IN (\\server\groupname.txt) DO (
echo Processing %%A
IF EXIST "\\%%A\c$\program files (x86)\Microsoft Office\Office16\Outlook.exe" (
xcopy /e /q "\\server\application" "\\%%A\c$\temp\application\"
) ELSE (
ECHO "Outlook 2016 was not detected, application not installed
)
)
Upvotes: 2