CA Client Automation

 View Only
  • 1.  DMS (IPS) script issue with MSIEXEC

    Posted Oct 01, 2019 07:03 AM
    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.
    ------------------------------


  • 2.  RE: DMS (IPS) script issue with MSIEXEC

    Posted Oct 01, 2019 10:45 AM
    Answering my own question...

    I've found that the line:
        If Not (Execute(sCmd,true,0)) then

    is not valid.
    Instead I changed the code to set a new integer variable to the result of the Execute command:
        iRes = (Execute(sCmd,true,0)

    then:
        If iRes <>0 then 'failed
        Else 'worked

    Painful and time consuming to come to this conclusion.  Also I just don't see the logic in not being able to do things my original way...

    ------------------------------
    Never trust a man who when left alone with a tea cosy doesn't try it on.
    ------------------------------



  • 3.  RE: DMS (IPS) script issue with MSIEXEC
    Best Answer

    Posted Oct 01, 2019 10:51 AM

    Hi Bob,

     

    I would try this:

     

    • Use cmd /c instead of start /wait
    • Use the full path to the MSI, which would be:
      • sMSIName = """"+argv(1)+"\"+argv(3)+""""
      • Note the usage of double quotes – there are FOUR at the beginning and end, which results in the whole string being quoted. This can get confusing but unfortunately " is the escape character. Also, remember to replace the quotes if you copy/paste from this post as MS Outlook uses so called 'smart-quotes'.
    • Add logging to the MSI command so you can see what MSIEXEC is returning:
      • sMSILogFile = """"+EnvGetString("TEMP")+"\MSI_LogFile.TXT"
      • sCmd = "start /wait msiexec.exe /i "+sMSIName+" /lv "+sMSILogFile
      • Append the MSI Log file to $rf

     

    Steve McCormick

     

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

    Broadcom

    Clarity Client Automation

      Post New Message

     

    DMS (IPS) script issue with MSIEXEC

    BOB LOMAX

    Oct 1, 2019 7:03 AM

    BOB LOMAX

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

      Reply to Group Online   View Thread   Recommend   Forward   Flag as Inappropriate  



     

     

    You are subscribed to "Clarity Client Automation" as stephen.mccormick@fiserv.com. To change your subscriptions, go to My Subscriptions. To unsubscribe from this community discussion, go to Unsubscribe.

    Copyright © 2005-2019 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

    Hosted by Higher Logic, LLC on the behalf of Broadcom - Privacy Policy | Cookie Policy | Supply Chain Transparency | Terms of Use






  • 4.  RE: DMS (IPS) script issue with MSIEXEC

    Posted Oct 01, 2019 11:44 AM
    Thanks Steve - much of what you suggest was/is now in my main script.
    I changed things to call the sd_msiexe CLI command within my script and removing the If Not (Execute... construct and installs are successful now.
    Just working on the uninstall process now as a standard MSI based Uninstall action won't work, so I'll have to script that too.

    ------------------------------
    Never trust a man who when left alone with a tea cosy doesn't try it on.
    ------------------------------