none
Unable to read the content of outputlog from msiexec command RRS feed

  • Question

  • Hi!

    I'm creating a installation script for installing .msi packages. To do this I'm using the msiexec command (http://technet.microsoft.com/en-us/library/cc759262(WS.10).aspx) that executes an silent install and writes the output to an log.

    When the installation has completed I want the script to read the logfile in order to determine if everything went as intended. However whenever my script reads the log created by msiexec, it fails since it seems unable to parse. The msgbox (where the content of the log is presented) ends up showing dubious symbols.

    Is this log in some invalid format that requires conversion of some sort? The only way a vba script is able to read the content is if I copy the content (using a txteditor such as Notepad++) to an entirely new file.

    This is my code so far, for the vbs-file:

    Option Explicit
    
    'Used for executing cmd commands
    Dim WshShell
    Set WshShell = CreateObject("wscript.Shell")
    
    'Current time stamp
    Dim strTimeStamp
    'Replace "/" with "_" so that we can create folders and files using this variable
    strTimeStamp = Replace(Date, "/", "-")
    'Replace ":" with "_" so that we can create folders and files using this variable
    strTimeStamp = strTimeStamp & "_" & Replace(time, ":", "")
    'Replace any space
    strTimeStamp = Replace(strTimeStamp, " ", "")
    
    'Used for checking content of logfile(s)
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Used to read content of various logfile
    Dim strResultLog
    
    'Used to temporarily store content of each row in logfile
    Dim strResultLogLine
    
    'Used for file handling
    Dim oFS
    
    '########### START MSI SETTINGS ###########
    'Path to the MSI-file
    Dim strMsiFile
    strMsiFile = "install_flash_player_11_plugin_64bit.msi"
    
    'Path and name to MSI install logfile
    Dim strMsiInstallLog
    strMsiInstallLog = "MsiInstall-log_" & strTimeStamp & ".txt"
    
    'Command for installing MSI
    Dim strMsiInstall
    strMsiInstall = "msiexec /qn /i " & strMsiFile & " /l*vx " & strMsiInstallLog
    
    '########### END MSI SETTINGS ###########
    
    
    '########### START INSTALL MSI FILE ###########
    'Run the command to install the MSI file
    wshShell.run "cmd /c" & strMsiInstall,0,True
    
    'Open the resultfile
    set oFS = objFSO.OpenTextFile(strMsiInstallLog)
    
    'Start reading the content of the resultfile
    Do Until oFS.AtEndOfStream
    	'Save each row in strResultLog
    	strResultLogLine = oFS.ReadLine
    	strResultLog = strResultLog & vbcrlf & strResultLogLine
    Loop
    'Done reading the content of resultfile, now closing the file
    oFS.close
    
    'Present the content of logfile in msgbox
    wscript.echo strResultLog
    
    '########### DONE INSTALL MSI FILE ###########
    


     You need to change the variable strMsiFile at rownumber 32, to let it point to a msi-file located in the same folder as the script. In this example I used an 64-bits installer for Flash. 32-bits msi-installers can be found here (if examples are needed):
    http://www.adobe.com/special/products/flashplayer/fp_distribution3.html  

    Ideas anyone?


    /Christian
    Thursday, January 5, 2012 1:45 PM

Answers

  • Turns out the main issue with the encoding of the log that the msi-installation produces.

    Spent some time trying to find some way of easily converting the encoding (was set to UCS-2 on the logfile). Then I found out something called "Tristate" that can be used when opening files in my script. For my details regarding tristate and it's uses see this page:
    http://www.devguru.com/technologies/vbscript/14075.asp 

    All I had to do was alter the line:
    set oFS = objFSO.OpenTextFile(strMsiInstallLog)

    To:
    set oFS = objFSO.OpenTextFile(strMsiInstallLog, 1, False, -2)
    Where "-2" is the "tristate-value" set to use the system default. And this little tweak of the code solved my issue! 


    /Christian
    Monday, January 9, 2012 3:13 PM

All replies

  • Turns out the main issue with the encoding of the log that the msi-installation produces.

    Spent some time trying to find some way of easily converting the encoding (was set to UCS-2 on the logfile). Then I found out something called "Tristate" that can be used when opening files in my script. For my details regarding tristate and it's uses see this page:
    http://www.devguru.com/technologies/vbscript/14075.asp 

    All I had to do was alter the line:
    set oFS = objFSO.OpenTextFile(strMsiInstallLog)

    To:
    set oFS = objFSO.OpenTextFile(strMsiInstallLog, 1, False, -2)
    Where "-2" is the "tristate-value" set to use the system default. And this little tweak of the code solved my issue! 


    /Christian
    Monday, January 9, 2012 3:13 PM
  • On second thought you might want to (in most cases) set tristate to -1. As I understand it is then reading the file in Unicode, which is handy if your writing a installationsscript as I am.
    /Christian
    Monday, January 9, 2012 3:20 PM