Script to install exe silently

Hi all;

I need to install an Outlook plugin ".exe" file to specific several PCs in the network. The plugin requires the following prerequisites to be installed that I would like to have the script install as well prior to the plugin:

a.      MS VSTO 2010 Runtime
b.      MS .NET Framework 4.0

I could generate an MSI from the EXE by running : setup.exe /b”<\PathToExtractMSI”>. Once that is done the MSI can be installed silently via the following command: msiexec /i “<\PathToMSI”> /quiet

The plugin comes in 2 architectures "x86 & x64". Therefore; I was wondering if there is a way to create a script "VBS, batch or PS" that would check for Outlook architecture and execute the compatible installer. What's more; the plug in is compatible with Outlook 2010 and above, so we also need to make sure that the script checks for Outlook's version and stop executing the script if the return result isn't Outlook 2010 and above.....

I know that I can check for Outlook architecture by:

if exist "C:\Program Files (x86)\Microsoft Office\Office15\outlook.exe" set OutlookArch=32
if exist "C:\Program Files\Microsoft Office\Office15\outlook.exe" set OutlookArch=64

Any suggestions... please advise.

Thanks.
Kinan Al-HaffarSenior Systems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Here's a batch script; if Outlook is not found or too old, it will exit with errorlevel 1.
Otherwise, you'll have two variables at the end, "OutlookVersion" (14 or higher) and "OutlookBitness" (x86 or x64).
@echo off
setlocal enabledelayedexpansion
set CurVer=
for /f "tokens=3" %%a in ('reg.exe query "HKCR\Outlook.Application\CurVer" /ve ^| find.exe /i "REG_SZ"') do set CurVer=%%a
if "%CurVer%"=="" (
	echo No Outlook installation found.
	exit /b 1
)
for %%a in (%CurVer:.= %) do set OutlookVersion=%%a
if %OutlookVersion% LSS 14 (
	echo This Outlook '%OutlookVersion%' is too old for the plugin.
	exit /b 1
)
set OutlookBitness=
for /f "tokens=3" %%a in ('reg.exe query "HKLM\SOFTWARE\Microsoft\Office\%OutlookVersion%.0\Outlook" /v "Bitness" ^| find.exe /i "REG_SZ"') do set OutlookBitness=%%a
if "%OutlookBitness%"=="" (
	echo Unable to determine the Outlook bitness; this should not have happened.
	exit /b 1
)
echo Detected Outlook version: '%OutlookVersion%'; bitness: '%OutlookBitness%'

Open in new window


And, for the fun of it, the same in Powershell:
If (-Not ($CurVer = (Get-ItemProperty "HKLM:\Software\Classes\Outlook.Application\CurVer" -ErrorAction SilentlyContinue)."(default)")) {
	"No Outlook installation found." | Write-Error
	Exit 1
}
[int]$OutlookVersion = $CurVer.Split(".")[-1]
If ($OutlookVersion -lt 14) {
	"Outlook version '$($OutlookVersion)' is too old for this plugin." | Write-Error
	Exit 1
}
If (-Not ($OutlookBitness = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Office\$($OutlookVersion).0\Outlook" -ErrorAction SilentlyContinue).Bitness)) {
	"Unable to determine the Outlook bitness; this should not have happened." | Write-Error
	Exit /b 1
}
"Detected Outlook version: '$($OutlookVersion)'; bitness: '$($OutlookBitness)'." | Write-Host -ForegroundColor Green

Open in new window


Edit: Added Powershell version.
Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thank you so much for the reply. What's more; the goal here is to have one script that runs the whole show:

1. Check the Outlook version and architecture and execute the compatible MSI file based on the result, or exit if Outlook is older than 2007 despite the architecture.
2. Run the msi installer in Silent mode and run the prerequisites prior to the plugin

The script then can be distributed via a GPO for instance...

Please advise.

Thanks again..
oBdACommented:
Just use something like this, after adjusting the msiexec arguments to your environment.
It's in test mode and will only display the msiexec commands it would normally run; remove the uppercase ECHOs to run it for real.
@echo off
setlocal enabledelayedexpansion
set CurVer=
for /f "tokens=3" %%a in ('reg.exe query "HKCR\Outlook.Application\CurVer" /ve ^| find.exe /i "REG_SZ"') do set CurVer=%%a
if "%CurVer%"=="" (
	echo No Outlook installation found.
	exit /b 1
)
for %%a in (%CurVer:.= %) do set OutlookVersion=%%a
if %OutlookVersion% LSS 14 (
	echo This Outlook '%OutlookVersion%' is too old for the plugin.
	exit /b 1
)
set OutlookBitness=
for /f "tokens=3" %%a in ('reg.exe query "HKLM\SOFTWARE\Microsoft\Office\%OutlookVersion%.0\Outlook" /v "Bitness" ^| find.exe /i "REG_SZ"') do set OutlookBitness=%%a
if "%OutlookBitness%"=="" (
	echo Unable to determine the Outlook bitness; this should not have happened.
	exit /b 1
)
echo Detected Outlook version: '%OutlookVersion%'; bitness: '%OutlookBitness%'

set Reboot=False
ECHO start "" /wait msiexec.exe /i "C:\vsto.msi" /quiet /noreboot /liewa "%Systemroot%\Temp\vsto.msi"
if %Errorlevel% neq 0 (
	if %Errorlevel% equ 3010 (
		set Reboot=True
	) else (
		echo Error %Errorlevel% during installation of VSTO.
		exit /b 1
	)
)

ECHO start "" /wait msiexec.exe /i "C:\framework.msi" /quiet /noreboot /liewa "%Systemroot%\Temp\framework.msi"
if %Errorlevel% neq 0 (
	if %Errorlevel% equ 3010 (
		set Reboot=True
	) else (
		echo Error %Errorlevel% during installation of the .NET Framework.
		exit /b 1
	)
)

set PluginMsi=WhatEver_%OutlookBitness%.msi
ECHO start "" /wait msiexec.exe /i "C:\%PluginMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\outlook-plugin.msi"
if %Errorlevel% neq 0 (
	if %Errorlevel% equ 3010 (
		set Reboot=True
	) else (
		echo Error %Errorlevel% during installation of the Outlook plugin.
		exit /b 1
	)
)

if %Reboot%==True (
	echo A reboot is required.
)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thank you so much. I will try it and post the results shortly.
Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
So I tried the script and it's running fine so far. However; I was wondering how can I based on the Outlook query result direct the script to install the x86 MSI or the x64 MSI?

Please advise.

Thank you.
oBdACommented:
As outlined in the last example starting in line 43: you can use the variable OutlookBitness, which is either x64 or x86.
Since you're not telling how the x86 and the x64 msi versions differ by name or install folder, that's as much detail as I can provide.
Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thank you for your reply. I apologize for not mentioning the required info. Here are the names and locations of both MSI files:

C:\Onyx_360_Install\Onyx360_Client_v7.6.1_x86\Onyx_360_for_Outlook_(x86).msi

C:\Onyx_360_Install\Onyx360_Client_v7.6.1_x86\Onyx_360_for_Outlook_(x64).msi

Thanks...
oBdACommented:
Then something like this should do the trick (they're really both in the "Onyx360_Client_v7.6.1_x86" folder?).
set PluginMsi=C:\Onyx_360_Install\Onyx360_Client_v7.6.1_x86\Onyx_360_for_Outlook_(%OutlookBitness%).msi
ECHO start "" /wait msiexec.exe /i "C:\%PluginMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\outlook-plugin.msi"
if %Errorlevel% neq 0 (
	if %Errorlevel% equ 3010 (
		set Reboot=True
	) else (
		echo Error %Errorlevel% during installation of the Outlook plugin.
		exit /b 1
	)
)

Open in new window

Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thank you.. assuming that they are in different folder, which I assume is better, do I need to have the above mentioned part of the script twice?

C:\Onyx_360_Install\Onyx360_Client_v7.6.1_x86\Onyx_360_for_Outlook_(x86).msi

C:\Onyx_360_Install\Onyx360_Client_v7.6.1_x64\Onyx_360_for_Outlook_(x64).msi
oBdACommented:
No, you'd just use the variable twice:
set PluginMsi=C:\Onyx_360_Install\Onyx360_Client_v7.6.1_%OutlookBitness%\Onyx_360_for_Outlook_(%OutlookBitness%).msi
ECHO start "" /wait msiexec.exe /i "C:\%PluginMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\outlook-plugin.msi"
if %Errorlevel% neq 0 (
      if %Errorlevel% equ 3010 (
            set Reboot=True
      ) else (
            echo Error %Errorlevel% during installation of the Outlook plugin.
            exit /b 1
      )
)
Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thanks... does this seems ok? decided to use a network share for the MSI installers, and have a separate folder for each installer based on the architecture, except for the DotNet since that one installer works for both...

@echo off

setlocal enabledelayedexpansion
set CurVer=
for /f "tokens=3" %%a in ('reg.exe query "HKCR\Outlook.Application\CurVer" /ve ^| find.exe /i "REG_SZ"') do set CurVer=%%a
if "%CurVer%"=="" (
	echo No Outlook installation found.
	exit /b 1
)
for %%a in (%CurVer:.= %) do set OutlookVersion=%%a
if %OutlookVersion% LSS 14 (
	echo This Outlook '%OutlookVersion%' is too old for the plugin.
	exit /b 1
)
set OutlookBitness=
for /f "tokens=3" %%a in ('reg.exe query "HKLM\SOFTWARE\Microsoft\Office\%OutlookVersion%.0\Outlook" /v "Bitness" ^| find.exe /i "REG_SZ"') do set OutlookBitness=%%a
if "%OutlookBitness%"=="" (
	echo Unable to determine the Outlook bitness; this should not have happened.
	exit /b 1
)
echo Detected Outlook version: '%OutlookVersion%'; bitness: '%OutlookBitness%'

set Reboot=False

taskkill /IM outlook.exe

set VstoMsi=\\corpbeacond02\Beacon_Install_Files\Onyx_360_Install\vstor_redist_%OutlookBitness%\vstor_redist_(%OutlookBitness%).msi
start "" /wait msiexec.exe /i "%VstoMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\Vsto.msi"
if %Errorlevel% neq 0 (
      if %Errorlevel% equ 3010 (
            set Reboot=True
      ) else (
            echo Error %Errorlevel% during installation of the Microsoft Vsto 2010 Runtime.
            exit /b 1
      )
)

set DotNetMsi=\\corpbeacond02\Beacon_Install_Files\Onyx_360_Install\dotNetFx40_Full_setup.msi
start "" /wait msiexec.exe /i "%DotNetMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\DotNet.msi"
if %Errorlevel% neq 0 (
      if %Errorlevel% equ 3010 (
            set Reboot=True
      ) else (
            echo Error %Errorlevel% during installation of the Microsoft DotNetFx.
            exit /b 1
      )
)

set pluginMsi=\\corpbeacond02\Beacon_Install_Files\Onyx_360_Install\Onyx360_Client_v7.6.1_%OutlookBitness%\Onyx_360_for_Outlook_(%OutlookBitness%).msi
start "" /wait msiexec.exe /i "%PluginMsi%" /quiet /noreboot /liewa "%Systemroot%\Temp\outlook-plugin.msi"
if %Errorlevel% neq 0 (
      if %Errorlevel% equ 3010 (
            set Reboot=True
      ) else (
            echo Error %Errorlevel% during installation of the Outlook plugin.
            exit /b 1
      )
)

if %Reboot%==True (
	echo A reboot is required.
)

Open in new window

oBdACommented:
If the msi paths are OK, then this should work.
Kinan Al-HaffarSenior Systems EngineerAuthor Commented:
Thank you so much for your help... I really appreciate it....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.