Deploy a .bat file to execute an .msi install for a program

We have a software program that will be used for backups however the .msi package doesn't configure the settings for us, therefore we were given a .bat file to deploy with the install.

My question is, how can I go about adding the .bat file to a certain OU in active directory and include the run path for the .msi install in the .bat file? We are hoping to make this happen silently.

I have attached the .bat, and right now I'm struggling on where I can input the run command for the .msi
nullogyAsked:
Who is Participating?
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.

Michael DyerSenior Systems Support AnalystCommented:
I do not see the batch file attached.  

Typically your batch file would install the product with something like this:

msiexec /i A:\Example.msi

look here for a full explanation of the command line options: http://technet.microsoft.com/en-us/library/bb490936.aspx
0
nullogyAuthor Commented:
Correction, please see the attached file.
CrashPlan.txt
0
Gabriel CliftonNet AdminCommented:
The last section is your installation. It executes the msi from the same directory as the script.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Michael DyerSenior Systems Support AnalystCommented:
This batch file figures out the users name and home folder and feeds this information to the installer.  You just have to put this batch file and the msi folder in a share on the network and then add this batch file as a script under logon properties in the group policy for the specific OU that you want to have this software.
0
Steve KnightIT ConsultancyCommented:
If this has been supplied by the software vendor it is frankly at least a bit "wrong".  You shouldn't refer to c:\users\username say but %userprofile% takes you straight to the logged on user... also it is getting the username in a bizarre way when you could use %username% and %userdomain% etc. and of course is including 32 bit and 64 bit options and the different paths for the profile doe you to edit for different machines.

The thing mainly I would consider though is do your users have rights to install the software?  If not then it is probably best installed for them, e.g. you could use the software installation settings against the user or computer OU in Active Directory, and then push the settings for the user down - I'd ask the vendor where they store these settings (and why) since it appears your config is just pushing the username and their profile directory as parameters, it can determine those for itself when it runs!

Steve
0
Gabriel CliftonNet AdminCommented:
Steve, I have seen scripts like this from vendors many times before, it is intended to run as one person, admin, yet copy files for the restricted user that is currently logged in. If no one is logged in and you are deploying it or if the admin is logged in, the script will not work right. The best way to guarantee someone is logged when when this script runs is have the script run after log on, like in a scheduled task.

This script is not ideal but could get you by.
0
nullogyAuthor Commented:
This is the process that I went ahead and followed however it did not work as of yet:

- Created the test GPO and linked it to the proper OU that I want it to be applied for, the link is enabled and security filtering is set for all domain computers to read access
- under group policy settings, went to computer configuration, policies, windows settings, scripts, startup, and added the .bat file
- I have the .bat and .msi located in the same shared folder however I'm not sure why the installation didn't kick off.
- I can cmd prompt gpresult /r and see that my test GPO was under the applied list

The only thing I can think of is the .bat doesn't know which .msi to run nor the location of it? I have them on the shared driver together, but how do they know to sync with one another? There's no indication in the .bat file to look at the .msi

Thanks
0
Gabriel CliftonNet AdminCommented:
This, %~dp0 tells the batch script to look in the same directory as the script. If someone is not logged in when the script is ran, it will fail.
0
nullogyAuthor Commented:
I went ahead and logged in as myself in order for the script to run however I do not see the program installed just yet.
0
Gabriel CliftonNet AdminCommented:
It is probably running before you log in. Create a gpo that makes a scheduled task after login.
0
Neil RussellTechnical Development LeadCommented:
Firstly I am not affiliated to ANY backup software company but if I was, I certainly wouldnt be affiliated to one that can not even provide you with an installer for its own product.

Two sayings from back home spring to mind when I see something like this appear on the net as the Latest and Greatest product....

Cheap no good and good no cheap!
also
If it sounds too good to be true then it probably is.

Is this using there "Business" Edition that you are setting up?
0
nullogyAuthor Commented:
So I went ahead and created a immediate task under computer configuration < preferences < Control panel settings < scheduled tasks.

In general, gave it the name and to run the task as the NT Authority\System, went to the actions tab and hit "start a program" and added the .bat file. Left conditions, settings and common alone.

The program still hasn't installed and I'm not sure what I'm missing here.
0
Michael DyerSenior Systems Support AnalystCommented:
You could add a line at the end of the batch file reading simply "pause" to hold the batch file open when it runs to see what error message, if any, is given.  You could also remove the /qn from the installation line near the end for testing.  /qn tells it to install in quiet mode with no user interface.  Removing this will tell it to show you the user interface which would let you see if the installation starts to run.    At this point it's probably something simple like an incorrect path.
0
nullogyAuthor Commented:
Please take a look at the attached image, this is the error that I get from event viewer. Let me know what you think and how I should proceed.
Untitled.png
0
Michael DyerSenior Systems Support AnalystCommented:
Be sure the account that is running the scheduled event is a local admin on the workstation.
0
Gabriel CliftonNet AdminCommented:
I think I see it, the msiexec.exe is missing on the install command.

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
REM MSIEXEC.EXE %~dp0CrashPlanPROe_Win.msi /qn /l %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.EXE %~dp0CrashPlanPROe-x64_Win.msi /qn /l %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%


Also, you can try it without the everything after the /I to see if the switches are wrong and you can change the /qn to /qb to see the installer run.
0
nullogyAuthor Commented:
Michael, we are on a domain, do I still need to have the local admin run? If so, how can I accomplish this?

I went ahead and attached the text version of the batch. Can you please show me where to make the changes?
0
Gabriel CliftonNet AdminCommented:
Also, if you are running 32bit windows 7 the remove the REM at line 34
0
Gabriel CliftonNet AdminCommented:
Change to this to accommodate Windows 7 32 bit and Windows 7 64 bit.

 
if defined programfiles(x86) goto x64

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
MSIEXEC.exe %~dp0CrashPlanPROe_Win.msi /qn /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%
pause
exit

:x64
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.exe %~dp0CrashPlanPROe-x64_Win.msi /qn /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

pause

Open in new window

0
nullogyAuthor Commented:
I went ahead and changed the install path to the attached .txt file and I have the same settings in control panel settings < scheduled tasks. It's set to run as an immediate task for windows 7. I'm currently testing and running this as my domain account for security settings.

I still get this error message attached.
CrashPlan.txt
Untitled.png
0
Michael DyerSenior Systems Support AnalystCommented:
Can you run it manually from the desktop and is that working?
0
Gabriel CliftonNet AdminCommented:
Can you try this to see what happens. Run it manually with the script and msi in the same folder. I have made it self elevating and I have added a write to event log on success or failure with msi error code, also if you get a failure it will attempt to install again without additional switches.

:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS 
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges 
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) 

:getPrivileges 
if '%1'=='ELEV' (shift & goto gotPrivileges)  
ECHO. 
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation 
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B 

:gotPrivileges 
::::::::::::::::::::::::::::
:START
::::::::::::::::::::::::::::
setlocal & pushd .

set retry=1

REM Script grabs currently logged in user and user home; installs silently. Compatible with running the installer as administrator or another user.
 
REM Determine which user lauched explorer.exe, trim out the domain
for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c
for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b
 
REM The LDAP login user name and the CrashPlan user name.
SET CP_USER_NAME=%_curruser%
ECHO UserName: %CP_USER_NAME%
 
REM The users home directory, used in backup selection path variables.
SET CP_USER_HOME=C:\Users\%_curruser%
REM SET CP_USER_HOME="C:\Documents and Settings\%_curruser%"
ECHO UserHome: %CP_USER_HOME%

REM The users home directory (Windows Vista and newer), used in backup selection path variables.
REM SET CP_USER_HOME=C:\Users\%_curruser%

REM The users home directory (Windows XP and older), used in backup selection path variables.
REM SET CP_USER_HOME=C:\Documents and Settings\%_curruser%

ECHO UserHome: %CP_USER_HOME%
 
REM Tells the installer not to run CrashPlan client interface following the installation.
SET CP_SILENT=true
ECHO Silent: %CP_SILENT%
 
SET CP_ARGS="CP_USER_NAME=%CP_USER_NAME%&CP_USER_HOME=%CP_USER_HOME%"
ECHO Arguments: %CP_ARGS%
 
if defined programfiles(x86) goto x64

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
MSIEXEC.exe %~dp0CrashPlanPROe_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

:x64
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.exe %~dp0CrashPlanPROe-x64_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

REM ================================================================================
REM ================ Installation successful. Write to Event Log====================
:ENDHERE
EVENTCREATE /l Application /so %UPN%-Install-SUCCESS /t SUCCESS /id 1000 /d "Application installed successfully."
Exit 0
REM ================================================================================

REM ================ Installation failed. Write to Event Log========================
:ERROR
if %retry% NEQ 1 exit /b
EVENTCREATE /l Application /so %UPN%-Install-FAILED--(ERROR=%MSIERROR%) /t ERROR /id 999 /d "Application installation failed."
Exit %MSIERROR%
REM ================================================================================

if defined programfiles(x86) goto x642

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
MSIEXEC.exe %~dp0CrashPlanPROe_Win.msi /qb
set retry=2

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

:x642
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.exe %~dp0CrashPlanPROe-x64_Win.msi /qb
set retry=2

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

pause
exit

Open in new window

0
nullogyAuthor Commented:
Take a look at the new batch file I created and let me know if you see any errors with it.

Source: -Install-FAILED--(ERROR=1639)
Event ID: 999
Application installation failed.

Michael, when I run it locally, I get no errors in event viewer and oddly enough nothing in application either.
0
Gabriel CliftonNet AdminCommented:
"Error 1639: Invalid command line argument."

Let's just strip the other stuff and try this
if defined programfiles(x86) goto x64

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
MSIEXEC.exe /i %~dp0CrashPlanPROe_Win.msi /qb
pause
exit

:x64
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.exe /i %~dp0CrashPlanPROe-x64_Win.msi /qb
pause

Open in new window

1
nullogyAuthor Commented:
Gabriel,

Thank you so much for writing that new script. That took care of the error message and the install came up. It was the goal of the script to include all the credentials for an existing account when the .msi kicks off. What would I need to add back to the script in order for the install to start, autofill the information?

Thanks!
0
Gabriel CliftonNet AdminCommented:
Go ahead and try this, after running look for a file called install-cmd.txt and post the contents.
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS 
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges 
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) 

:getPrivileges 
if '%1'=='ELEV' (shift & goto gotPrivileges)  
ECHO. 
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation 
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B 

:gotPrivileges 
::::::::::::::::::::::::::::
:START
::::::::::::::::::::::::::::
setlocal & pushd .

set retry=1

REM Script grabs currently logged in user and user home; installs silently. Compatible with running the installer as administrator or another user.
 
REM Determine which user lauched explorer.exe, trim out the domain
for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c
for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b
 
REM The LDAP login user name and the CrashPlan user name.
SET CP_USER_NAME=%_curruser%
ECHO UserName: %CP_USER_NAME%
 
REM The users home directory, used in backup selection path variables.
SET CP_USER_HOME=C:\Users\%_curruser%
REM SET CP_USER_HOME="C:\Documents and Settings\%_curruser%"
ECHO UserHome: %CP_USER_HOME%

REM The users home directory (Windows Vista and newer), used in backup selection path variables.
REM SET CP_USER_HOME=C:\Users\%_curruser%

REM The users home directory (Windows XP and older), used in backup selection path variables.
REM SET CP_USER_HOME=C:\Documents and Settings\%_curruser%

ECHO UserHome: %CP_USER_HOME%
 
REM Tells the installer not to run CrashPlan client interface following the installation.
SET CP_SILENT=true
ECHO Silent: %CP_SILENT%
 
SET CP_ARGS="CP_USER_NAME=%CP_USER_NAME%&CP_USER_HOME=%CP_USER_HOME%"
ECHO Arguments: %CP_ARGS%
 
if defined programfiles(x86) goto x64

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
echo MSIEXEC.exe /i %~dp0CrashPlanPROe_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT% >install-cmd.txt
MSIEXEC.exe /i %~dp0CrashPlanPROe_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

:x64
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
ECHO MSIEXEC.exe /i %~dp0CrashPlanPROe-x64_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT% >install-cmd.txt
MSIEXEC.exe /i %~dp0CrashPlanPROe-x64_Win.msi /qb /l* %USERNAME%_install.log CP_ARGS=%CP_ARGS% CP_SILENT=%CP_SILENT%

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

REM ================================================================================
REM ================ Installation successful. Write to Event Log====================
:ENDHERE
EVENTCREATE /l Application /so %UPN%-Install-SUCCESS /t SUCCESS /id 1000 /d "Application installed successfully."
Exit 0
REM ================================================================================

REM ================ Installation failed. Write to Event Log========================
:ERROR
if %retry% NEQ 1 exit /b
EVENTCREATE /l Application /so %UPN%-Install-FAILED--(ERROR=%MSIERROR%) /t ERROR /id 999 /d "Application installation failed."
Exit %MSIERROR%
REM ================================================================================

if defined programfiles(x86) goto x642

REM 32-bit Windows installer. You can use any of the msiexec command-line options.
ECHO Installing CrashPlan...
MSIEXEC.exe /i %~dp0CrashPlanPROe_Win.msi /qb
set retry=2

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

:x642
REM 64-bit Windows installer. You can use any of the msiexec command-line options.
MSIEXEC.exe /i %~dp0CrashPlanPROe-x64_Win.msi /qb
set retry=2

set MSIERROR=%errorlevel%
if %MSIERROR%==0 GOTO :ENDHERE
if %MSIERROR%==1641 GOTO :ENDHERE
if %MSIERROR%==3010 GOTO :ENDHERE
GOTO :ERROR

pause
exit

Open in new window

0

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
nullogyAuthor Commented:
Heres the result:

MSIEXEC.exe /i \\ServerName\GPO\CrashPlanPROe-x64_Win.msi /qb /l* username_install.log CP_ARGS="CP_USER_NAME=username&CP_USER_HOME=C:\Users\username" CP_SILENT=true

However, I don't think the script includes the setup information such as the existing account username, password and server address?
0
Gabriel CliftonNet AdminCommented:
I am assuming you changed the \\ServerName and the username in place of the actual server name and user name which is good in that the top part of the script is working. It will not be able to have username or password. the way the script was designed, it is intended to be ran while the user is logged in on the computer which is why it would be better to run after login like scheduled task and a set wait period. Did the installer run this time?
0
nullogyAuthor Commented:
Yes the installer ran this time but from what I gather, I could just install this .msi via  a group policy or through Meraki. I thought the script would contain the details for the .msi to install on its own with the username, password and server address. Is there anyway to add that to the script?
0
Gabriel CliftonNet AdminCommented:
The way the script it's written, it writes info for user currently logged in. If you want user name and password you would need a script for each user.
0
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
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.