While working on a script for an upcoming project, I wanted to test for the presence of various Office versions, including 32-bit and 64-bit components before initiating setup. Here’s one way I found:
@ECHO OFF SET CURRLOCATION32="C:\Program Files (x86)\MicrosoftOffice\root\Office16" SET CURRLOCATION64="C:\Program Files\MicrosoftOffice\root\Office16" SET PREV1LOCATION32="C:\Program Files (x86)\MicrosoftOffice\root\Office15" SET PREV1LOCATION64="C:\Program Files\MicrosoftOffice\root\Office15" SET PREV2LOCATION32="C:\Program Files (x86)\MicrosoftOffice\root\Office14" SET PREV2LOCATION64="C:\Program Files\MicrosoftOffice\root\Office14" REM Check for 64-bit versions IF EXIST ""%CURRLOCATION64%\MANIFEST.XML"" SET _OPP64A=1 IF EXIST ""%PREV1LOCATION64%\MANIFEST.XML"" SET _OPPP64B=1 IF EXIST ""%PREV2LOCATION64%\MANIFEST.XML"" SET _OPP64C=1 REM Check for 32-bit versions IF EXIST ""%CURRLOCATION32%\MANIFEST.XML"" SET _OPP32A=4 IF EXIST ""%PREV1LOCATION32%\MANIFEST.XML"" SET _OPP32B=4 IF EXIST ""%PREV2LOCATION32%\MANIFEST.XML"" SET _OPP32C=4 SET BIT=0 FOR %%i in (%_OPP64A%,%_OPP64B%,%_OPP64C%,%_OPP32A%,%_OPP32B%,%_OPP32C%) DO ( SET /A BIT+="(%BIT% + %%i)" ) REM IF %BIT% GEQ 4 \\server\share\Office16\setup.exe /config \\server\share\Office16\ProPlus.WW\ConfigX32.xml REM IF %BIT% LEQ 3 \\server\share\Office16\setup.exe /config \\server\share\Office16\ProPlus.WW\ConfigX64.xml
What ways can you think of?