Solved

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

Posted on 2014-12-12
30
634 Views
Last Modified: 2014-12-17
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
0
Comment
Question by:nullogy
  • 12
  • 11
  • 5
  • +2
30 Comments
 
LVL 14

Expert Comment

by:Michael Dyer
ID: 40497354
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
 

Author Comment

by:nullogy
ID: 40497365
Correction, please see the attached file.
CrashPlan.txt
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40497376
The last section is your installation. It executes the msi from the same directory as the script.
0
 
LVL 14

Expert Comment

by:Michael Dyer
ID: 40497386
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40497420
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40497424
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
 

Author Comment

by:nullogy
ID: 40497430
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40497436
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
 

Author Comment

by:nullogy
ID: 40497444
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40497468
It is probably running before you log in. Create a gpo that makes a scheduled task after login.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40497786
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
 

Author Comment

by:nullogy
ID: 40501554
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
 
LVL 14

Expert Comment

by:Michael Dyer
ID: 40501635
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
 

Author Comment

by:nullogy
ID: 40501681
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
 
LVL 14

Expert Comment

by:Michael Dyer
ID: 40501691
Be sure the account that is running the scheduled event is a local admin on the workstation.
0
Do email signature updates give you a headache?

Do you feel like all of your time is spent managing email signatures? Too busy to visit every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40501699
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
 

Author Comment

by:nullogy
ID: 40501703
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40501708
Also, if you are running 32bit windows 7 the remove the REM at line 34
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40501712
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
 

Author Comment

by:nullogy
ID: 40502960
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
 
LVL 14

Expert Comment

by:Michael Dyer
ID: 40503030
Can you run it manually from the desktop and is that working?
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40503040
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
 

Author Comment

by:nullogy
ID: 40503105
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40503242
"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

0
 

Author Comment

by:nullogy
ID: 40503280
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
 
LVL 13

Accepted Solution

by:
Gabriel Clifton earned 500 total points
ID: 40503299
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
 

Author Comment

by:nullogy
ID: 40503328
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40503376
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
 

Author Comment

by:nullogy
ID: 40503405
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
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40503683
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now