MSI installer does not install when executed from a batch file - batch-file

I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause

The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.

Related

Retrieve .msi to run - * wildcard not working for name

So, there is always one installer (msi) in a folder for install generation, but the name changes many times. I tried doing the following:
"C:\Windows\system32\msiexec.exe" /i "C:\test\*.msi" /qn
But sadly, this doesn't work and complains. How can we get the name of the single msi in the folder, and plonk it into the command?
I'm using jenkins and using the "Execute windows batch command" item
Perhaps use a for loop to find all .msi files in that directory, and run it accordingly (obviously if there is more than one .msi you will need to tweak this logic):
for /r "C:\test" %%a in (*.msi) do msiexec /i "%%~dpnxa" /qn

Writing a script to look for a folder and run a batch file in it

I have a really messy program in my environment that basically has a jump client on over 7000 machines in my environment. When I upgrade the appliance that the jump client talks to it starts an in place upgrade but if there are computers off or off the network obviously the upgrade times out. Problem is, I cant mass deploy the updated jump client because the previous version has to be uninstalled first.
WMIC uninstaller doesn't work, msiexec uninstaller doesn't work. There is a batch file built into the program stored at %ProgramData%\ClientNameRandomNumbers. Problem is, you can also install a dissolvable client in the moment if needed and everytime the dissolvable client installs, it doesn't clean up after itself. So you have random folders that may or may not be the one that contains the uninstall.bat batch file that I need to run. I wanted to write a script to mass deploy that will start that batch file on each computer but I am having problems.
Basically I want it to search for the folder with a wild card, if it finds it CD to that directory and then try to run the uninstall, if it can't find the uninstall, continue through to deleting the folder as it is an old shell folder. And then go back and look for more folders until it can't find anymore and then go to exit.
This is what I have:
:START
cd %programdata%\bomgar-scc* || IF ERRORLEVEL not = 0 GOTO END
start uninstall.bat /Wait || cd c:\programdata &&
rd C:\programdata\bomgar-scc*
GOTO START
pause
:END
EXIT
Any suggestions?
I think I am understanding your requirements but maybe not. I have commented the code to let you know what it is doing.
#echo off
REM For command will attempt to find all folders
REM that start with bomgar-scc in the programdata folder
for /d %%G IN ("%programdata%\bomgar-scc*") do (
REM If it finds a folder check if an uninstall.bat
REM exists and run the batch file if it does exist.
IF EXIST "%%~G\uninstall.bat" CALL "%%~G\uninstall.bat"
REM Remove the directory found
rd "%%~G"
)
Create a Jump client MSI installer. Run the following command to uninstall it.
msiexec.exe /x "\%networkpath%\bomgar-scc-win64.msi" /quiet

In batch script silent installation using Reboot=reallysuppress is not updating the files

I am using batch Script for silent Installation to update the locked and in use files.Using silent installation reboots my system automatically after the update.But I wanna setup a custom reboot message box , So I used the REBOOT=ReallySuppress attribute. And I used a message box to popup the custom reboot message. This helps me avoid the auto-reboot of the system but it is not updating the files even after performing a manual reboot.
Here is the script that I am using.
#echo off
title Installing Updates
msiexec /i "C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi" /qn /REBOOT=ReallySuppress
echo updates installed
echo msgbox "Restart your system to complete the installation." > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"
pause >NUL
shutdown.exe /r /t 000
Can someone give me a solution to get the files updated with manual reboot.
did you try instead of /REBOOT=ReallySuppress the /norestart option?
Please also make a log file in the install cammand via /l option. Then read the log if really the installer reboots the computer.

How to let msi package install process take place in cmd instead of windows installer gui

How can I make a batch file that automatically installs java,office and adobe stuff without gui, instead of that I want to let whole proces take place inside the command prompt. For example I want to have a bar inside the command prompt telling me how far the install process is. How do I make that, I can't find it on the internet. Here is a example of what I already have:
#echo off
echo Installing application...
msiexec.exe /passive /i "%~dp0skypesetup.msi"
echo Install failed.
pause
Here I have the msi file if you wanna help me: http://www.skype.com/go/getskype-msi
Does anyone knows how to make a program with percent bar inside the command promt?
For the external GUI you can check MsiSetExternalUI function (follow the links). For installing silently the basic msiexec.exe command line is:
msiexec.exe /I "C:\MsiFile.msi" /QN /L*V "C:\msilog.log"
Quick explanation:
/I is for install
/QN is silent mode
/L*V is verbose logging
Some links:
Silent Install of MSI
What is different about a silent installation session
Common msiexec.exe command lines
Here is an answer that discusses alternative ways to install a package without using msiexec.exe
How to disable an extra window to restart system even after selecting not to do so in files in use dialog in installshield
Stupid me :( , I'v searched a lot and finally found it. I thought I had to use msi but I can also do it with .exe files. Stupid me.
Here's the code if someone wants it or needs it:
#ECHO OFF
echo Do you want to install ccleaner
pause
ccleaner.exe /S /L=1043
echo You've succesfully installed ccleaner
pause

Checking for existing file in C drive and then running an installer for batch

I`m trying to code a batch file that checks whether a file exists in my c drive.
If it exists , it will end the batch file.
if not, it will run an MSI file.
I got it to run the MSI file , however after installing it.
The checks do not work and it keeps prompting me to install the file.
I have attached the code that i have written.
And also is there any way to do a slient install of MSI in batch?
May i know what is wrong with the code?
if exist "C:\Program Files (x86)\Common Files\hi.txt" goto END
msiexec /i "\\computer-name\Test\setup.msi"
:END
You could do the silent install by typing >nul after msiexec /i "\\computer-name\Test\setup.msi"
So, it would look like this:
msiexec /i "\\computer-name\Test\setup.msi">nul
This works on my computer, I hope it works for you too :)

Resources