July 11, 2012

Updating an xml file using VBScript Custom Action

  1. Create a VBScript Custom Action stored in Binary Table (MSI Type Number: 6)
  2. Here is the Sample xml file (say address.xml), which is considered for updating in the below VBScript CA
         <Address>
              <Name>Smitha</Name>
              <Address1>123B, 16th Cross</Address1>
              <City>Bangalore</City>
         </Address>
  3. Write the following code in the VBScript file
Function UpdateXMLFile
     On Error Resume Next               
         
    Set objDOM  = CreateObject("Microsoft.XMLDOM")
    Set objParentNode = CreateObject("Microsoft.XMLDOM")    
    if Err.Number = 0 then             
          
                       ' Declaration
                       
dim FileName
                       dim name
                   
   dim address1
                     
  dim city
   Set objNet = CreateObject("WScript.NetWork")                
   set objNet=nothing                
              
    name=Session.Property("NAME")    
    address1=Session.Property("ADDRESS1")
    city=Session.Property("CITY")
 
     'update address.xml file
      FileName= Session.Property("INSTALLDIR")+"\"+"address.xml" 
      objDOM.async = false  
      objDOM.load(FileName)                                                
     if (trim(name)<>"" and trim(address1)<>"" and trim(city)<>"") then
         ' update name
          strXPath = "
/Address/@Name"
          set objParentNode = objDOM.selectSingleNode(strXPath)
          objParentNode.text = name           
 
         ' update address1
          strXPath = "
/Address/@Address1"
          set objParentNode = objDOM.selectSingleNode(strXPath)
          objParentNode.text = address1           
 
        ' update name
         strXPath = "
/Address/@City"
         set objParentNode = objDOM.selectSingleNode(strXPath)
         objParentNode.text = city 
  
         objDOM.Save(FileName)
                     end if
                 end if
           end function ' End of UpdateXMLFile

  4.    Set the following properties for the Custom Action (RestartIIS)

  Script Function -> UpdateXMLFile
  Return Processing -> Synchronous (Check exit code)
  In-Script Execution -> Immediate Execution
  Install Exec Sequence -> After InstallFinalize
  Install Exec Condition -> &FeatureA=3 and Installed.
This condition means that FeatureA is selected for installation and the FeatureA is installed (Installed state will be true as the CA is scheduled to execute after InstallFinalize).       

  [Note: This code snippet is tested with InstallShield 2012 Basic MSI Project. Should be compatible with earlier versions of InstallShield as well.]

July 10, 2012

Restarting IIS in MSI using VBScript Custom Action

This article focus on writing a Simple VBScript Custom Action to Restart IIS.

1. Create a VBScript Custom Action (RestartIIS) Stored in Binary Table (MSI Type Number: 6)

2. Write the following code in the VBScript file
Function RestartIIS()
     Set wsShell = CreateObject("WScript.Shell")
     Set fso = CreateObject("Scripting.FileSystemObject")

     winPath = WsShell.ExpandEnvironmentStrings( "%windir%" )
     netPath = fso.BuildPath( winPath, "system32" )
     toolPath = fso.BuildPath( netPath, "iisreset.exe" )
     WsShell.Run toolPath, 0, true
     set fso=nothing
     set WsShell=nothing  
End Function
3. Set the following properties for the Custom Action (RestartIIS) 
    Script Function -> RestartIIS
    Return Processing -> Synchronous (Check exit code)
    In-Script Execution -> Immediate Execution
    Install Exec Sequence -> After InstallFinalize
    Install Exec Condition -> &FeatureA=3 and Installed
                                           This condition means that FeatureA is selected for installation and the FeatureA is installed (Installed state will be true as the CA is scheduled to execute after InstallFinalize).
[Note: This code snippet is tested with InstallShield 2012 Basic MSI Project. Should be compatible with earlier versions of InstallShield as well.]

July 2, 2012

How to set Focus on your Installer dialog?

When we run an installer, sometimes the control switches between your installer and other application's screen, which might shift the focus from the installer dialog.

Here is how you can make sure to stay on top of your installer dialog unless you swtich explictly.

Call the function - SetInstallerDlgFocus(), before invoking each dialog, so that your installer will be always available in the foreground.

// Included header files
#include "WinApi.h"  // Required to Make Win32 API Calls

// Function declaration
prototype SetInstallerDlgFocus();

// Function definition
///////////////////////////////////////////////////////////////////////////////
//  FUNCTION:   SetInstallerDlgFocus
//  Purpose:    Bring window to the foreground. 
///////////////////////////////////////////////////////////////////////////////
function SetInstallerDlgFocus()
    HWND hDialog;
begin
      hDialog = GetWindowHandle(HWND_INSTALL);
      SetForegroundWindow(hDialog);
end; // end of SetInstallerDlgFocus


[Note: This applies to InstallScript MSI and Pure InstallScript type projects.]

June 28, 2012

Custom Action Types - Simplified

The following table categorizes the basic types of custom actions
Custom Action Types

SCM Tools -> A Comparison


This article focuses on a high level comparison of Source Control Management Software like TFS, Seapine Surround, Subversion and Git 

SCM Tools Comparison


The above table is based on my understanding and any suggestions / comments are welcome.