Tuesday, December 6, 2011

How to launch log file after completing install

This sample shows how to launch installation log after the installer finishes. The sample is developed in InstallScript MSI project using InstallShield 2012.


In order to launch a log file after your installer runs you need to follow three steps:

  1. Get the log file path
  2. Add checkbox to SdFinish dialog
  3. If checkbox is checked launch the log file in Notepad
Now let's look at these steps in detail.


  • To get a log file, enable logging by going to General Information tab in your InstallShield IDE and select 'Yes' for 'Create MSI Logs'. 
  • Next you need to set log file name, so that each time you don't have to figure it out. For this, you need to go to Releases > Setup.exe tab and provide Command-Line parameter as shown in the screenshot below. 
  • Next step would be to add a checkbox to SdFinish dialog. Go to Dialog Editor, select SdFinish dialog and edit it to add a new checkbox. Note the Control Identifier. 
  • Next, go to Behavior and Logic > InstallScript view add the SdFinish code by selecting Dialog Source in first Dropdown at top of the screen and SdFinish in second dropdown. Code for SdFinish will automatically be added to your InstallScript. Edit it to add code shown below to case SD_PBUT_CONTINUE

  // 1301 is Control Identifier for 'Launch log after finish' Checkbox on SdFinish dialog.
  if(CtrlGetState( szDlg, 1301 ) = BUTTON_CHECKED) then
  LaunchLogAfterFinish = TRUE;
 endif;


  • Next select 'AfterMoveData' from first dropdown and 'OnEnd' event in the second. Your OnEnd event should have code similar to:


function OnEnd()
         STRING logFilePath, NotePadEXE;
         NUMBER nResult;
begin
if( !REMOVEONLY ) then // So that you don't execute the same on uninstall..
//nResult = AskYesNo("Do you want to view log file now?", YES);
if(LaunchLogAfterFinish = TRUE) then
NotePadEXE = WindowsFolder + "\\Notepad.exe"; logFilePath = TempFolder + "\\Verbose_Log.txt";
LaunchApp(NotePadEXE, logFilePath); endif; endif;
end;

That's it. Build the installer and run it, it should launch the log file now.



You can download the sample here.

No comments:

Post a Comment