Link to home
Start Free TrialLog in
Avatar of nullogy
nullogy

asked on

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
Avatar of Michael Dyer
Michael Dyer
Flag of United States of America image

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
Avatar of nullogy
nullogy

ASKER

Correction, please see the attached file.
CrashPlan.txt
The last section is your installation. It executes the msi from the same directory as the script.
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.
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
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.
Avatar of nullogy

ASKER

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
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.
Avatar of nullogy

ASKER

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.
It is probably running before you log in. Create a gpo that makes a scheduled task after login.
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?
Avatar of nullogy

ASKER

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.
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.
Avatar of nullogy

ASKER

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
Be sure the account that is running the scheduled event is a local admin on the workstation.
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.
Avatar of nullogy

ASKER

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?
Also, if you are running 32bit windows 7 the remove the REM at line 34
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

Avatar of nullogy

ASKER

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
Can you run it manually from the desktop and is that working?
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

Avatar of nullogy

ASKER

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.
"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

Avatar of nullogy

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nullogy

ASKER

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?
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?
Avatar of nullogy

ASKER

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?
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.