Hi all,
I'm writing an IPS script and want to execute msiexec to install from an MSI file, rather than using the MSI option direct in a software delivery package configuration. This is because I want to run the MSI install and then follow it up with configuration file overwrites and a stop/start of a critical service to make sure the software runs with customer specific values.
I realise this could be done in more than one way, but I want to nail the execution of msiexec from within a script anyway.
As you can probably guess, I can't get this to work as I would like at the moment.
I have written the IPS script as follows:
' --------------------------------------------------------------
' Scripted installer
' Bob Lomax
' September 2019
'
' Initialise
DIM sCmd as String
DIM sLogRF as String
DIM sMSIName as String
DIM iLogFile as Integer
Print("Variable DIM statements done")
SetStatus(1)
Print("Current Status set to One - assume failed until setting Zero at end")
sMSIName = argv(3) ' MSI name has no spaces in it
' sCmd = "AgentMSI.cmd" ' no difference to running direct inside the script, tried each option below (with parameterised and hardcoded MIS name options)
' sCmd = "call msiexec.exe /i "+sMSIName ' doesn't install but job succeeds
sCmd = "start /wait msiexec.exe /i "+sMSIName ' doesn't install but job succeeds
' sCmd = "msiexec.exe /i "+sMSIName ' installs but the job step errors & script stops
' sCmd = "Powershell; Start-Process -Wait -FilePath msiexec.exe -ArgumentList /i, "+sMSIName ' left field attempt using PS, doesn't install but job succeeds
' Open Log File
sLogRF = argv(2)
iLogFile = OpenFile(sLogRF,O_WRITE,O_TEXT)
' Log all arguments and variables
WriteFile(iLogFile,"Scripted installer - "+argv(0))
WriteFile(iLogFile,"Package Path - "+argv(1))
WriteFile(iLogFile,"Response File - "+argv(2))
WriteFile(iLogFile,"MSI Name - "+sMSIName)
WriteFile(iLogFile,"MSI Command - "+sCmd)
' Additional print statements for debug purposes
Print("Arguments - "+argv(0)+" "+argv(1)+" "+argv(2))
Print("Variables - "+sMSIName+" "+sCmd)
' Execute the MSI installer command
If Not (Execute(sCmd,true,0)) then
WriteFile(iLogFile,"Failed to execute MSI command")
Print("Failed to execute MSI command")
Goto END
Else
WriteFile(iLogFile,"MSI Install successful")
Print("MSI Install successful")
EndIf
SetStatus(0) ' To get here things must have worked
WriteFile(iLogFile,"Set Status to Zero - to get here things must have worked")
Print("Set Status to Zero - to get here things must have worked")
END:
WriteFile(iLogFile,"At END - closing Log")
Print("At END - closing Log")
CloseFile(iLogFile)
The script is passed three parameters by the install procedure: "$ip $rf MSIfilename"
The commented variations of the sCmd string are things that I've tried in order to get the script to wait or pickup a return code of zero, as I think this is perhaps part of the problem.
This is output from the plain msiexec command use, which does install the software, but errors:
Scripted installer - GenericScriptInstaller.ips
Package Path - Y:\activate\393F88C2-CA05-478E-8B2A-E0733CD7C9D9.itm
Response File - C:\PROGRA~2\CA\DSM\Agent\units\00000001\usd\sdjexec\9CF13E20-7401-45C8-984B-3AE4A57B1C41.res
MSI Name - Agent-6.0.2.x64.msi
MSI Command -
msiexec.exe /i Agent-6.0.2.x64.msi
Failed to execute MSI command
At END - closing Log
This is output from adding a start /wait prefix, which does nothing when the job runs, but somehow the execute succeeds:Scripted installer - GenericScriptInstaller.ips
Package Path - Y:\activate\393F88C2-CA05-478E-8B2A-E0733CD7C9D9.itm
Response File - C:\PROGRA~2\CA\DSM\Agent\units\00000001\usd\sdjexec\97D2E3EE-AF06-4FA0-9F66-0BEEFA02A4EC.res
MSI Name - Agent-6.0.2.x64.msi
MSI Command - start /wait msiexec.exe /i Agent-6.0.2.x64.msi
MSI Install successful
Set Status to Zero - to get here things must have worked
At END - closing Log
I have tried putting my command strings into both .cmd and .bat files and then invoking those via execute instead of direct command strings - it makes no difference whichever variant I try.
I also tried getting the command/batch files to exit/echo with a zero %ERRORCODE% or fixed 0 value - again no difference.
Now I'm stuck - any ideas, comments, questions?
Kind regards,
Bob.
------------------------------
Never trust a man who when left alone with a tea cosy doesn't try it on.
------------------------------