Skip to content

Set silent installation fucntions to use in MSI custom actions.

August 9, 2013

Sub Trigger_Uninst_EMC()

 RdeInstallDir = Session.Property(“RdeProgramFolder”)

 Set ws = CreateObject(“WScript.Shell”)
 Set objFSO = CreateObject(“Scripting.FileSystemObject”)
 
 Manager_Location = objFSO.BuildPath(RdeInstallDir, “\rdmc.exe”)
 
 If objFSO.FileExists(Manager_Location) Then 

  WriteMessageToMsiLog “Deployment Manager was found, it is being triggered to remove the product.”
        rdmcCmd = “””” + Manager_Location + “”” _startPage=UninstallDirect_PAGE _web=1 _logLevel=5 _sso=0″

  WriteMessageToMsiLog “Deployment Manager command called: ” & rdmcCmd
  
  Session.Property(“ExitUninst”) = “1”
  ws.exec rdmcCmd
 Else
  WriteMessageToMsiLog “Deployment Manager was not found at this location: ” + Manager_Location
  WriteMessageToMsiLog “The msi will proceed with uninstallation.”
 End If

 WriteMessageToMsiLog “Custom Action [Trigger_Uninst_EMC] reached the end successfully.”

End Sub

‘—————————————————————————————————-

Sub Trigger_Uninst_EMC_Silent()

 RdeInstallDir = Session.Property(“RdeProgramFolder”)

 Set ws = CreateObject(“WScript.Shell”)
 Set objFSO = CreateObject(“Scripting.FileSystemObject”)

 Manager_Location = objFSO.BuildPath(RdeInstallDir, “\rdmc.exe”)
 If objFSO.FileExists(Manager_Location) Then 

  WriteMessageToMsiLog “Deployment Manager was found, it is being triggered to remove the product.”
  rdmcCmd = “””” + Manager_Location + “”” _silentMode=1 _execute=UNINSTALL”
  WriteMessageToMsiLog “Deployment Manager command called: ” & rdmcCmd
  Session.Property(“ExitUninstSilent”) = “1”
  ws.exec rdmcCmd
 Else
  WriteMessageToMsiLog “Deployment Manager was not found at this place: ” + Manager_Location
  WriteMessageToMsiLog “The msi will proceed with uninstallation.”
 End If

 WriteMessageToMsiLog “Custom Action [Trigger_Uninst_EMC_Silent] reached the end successfully.”

End Sub

‘—————————————————————————————————-

Function Exit_Uninst()

 Const IDCANCEL = 2
    Const IDABORT =  3

 WriteMessageToMsiLog “Exit_Uninst – Exiting with failure, this is done on purpose after calling Deployment Manager.”
 WriteMessageToMsiLog “Custom Action [Exit_Uninst] reached the end successfully.”
    Exit_Uninst = IDCANCEL

End Function

‘———————————————————————————————————–

Sub Trigger_Inst_EMC_Silent()

  SourceDir = Session.Property(“SourceDir”)
  InstallDir = Session.Property(“INSTALLDIR”)
  ProductName = Session.Property(“ProductName”)
  RdeDefineFolder = Session.Property(“RdeDefineFolder”)
  
    
  WriteMessageToMsiLog “SourceDir : ” & SourceDir
  WriteMessageToMsiLog “InstallDir : ” & InstallDir
  
  Set fso = CreateObject(“Scripting.FileSystemObject”)
  
  SourceDir = fso.GetParentFolderName(SourceDir)
  
  ProgramPath = fso.BuildPath(SourceDir, “\Files\Program\”)
  RDMCPath = fso.BuildPath(ProgramPath, “RDMC.exe”)
  
  If fso.FileExists(RDMCPath) Then
   
   WriteMessageToMsiLog RDMCPath & ” exist.”
   Set ws = CreateObject(“WScript.Shell”)
   
   ‘Create the new InstallWorkflow_MSI.xml
   
   InstallWorkflow_MSI_Name = “InstallWorkflow_MSI.xml”
   TempDir = ws.ExpandEnvironmentStrings(“%temp%”)
   InstallWorkflow_MSI_Path = fso.BuildPath(TempDir, InstallWorkflow_MSI_Name)
   
   Set InstallWorkflow_MSI_File = fso.CreateTextFile(InstallWorkflow_MSI_Path, True)
   InstallWorkflow_MSI_File.WriteLine(“<?xml version=””1.0″”?>”)
   If InStr(1, ProductName, “64bit”, 1) > 0 Then
    InstallWorkflow_MSI_File.WriteLine(“<install ExcelTarget=””x64″”>”) 
   Else
    InstallWorkflow_MSI_File.WriteLine(“<install>”) 
   End If
   InstallWorkflow_MSI_File.WriteLine(“<copy source=”””& SourceDir &”\Files”” target=””” & InstallDir & “””/>”) 
   InstallWorkflow_MSI_File.WriteLine(“<switch/>”) 
   InstallWorkflow_MSI_File.WriteLine(“</install>”) 
   InstallWorkflow_MSI_File.Close
   
   WriteMessageToMsiLog “Create ” & InstallWorkflow_MSI_Path
     
   rdmcCmd = “””” & ProgramPath + “rdmc.exe”” _silentMode=1 _execute=INSTALL _InstallWorkflow=””” & InstallWorkflow_MSI_Path & “”” _scriptLogLevel=5 _logFilePath=””” & RdeDefineFolder & “TRD 6\Logs\”””
   
   WriteMessageToMsiLog “Run command: ” & rdmcCmd

   ReturnMsg = ws.Run (rdmcCmd,0,True)
   
   WriteMessageToMsiLog “Finish command: ” & rdmcCmd
   WriteMessageToMsiLog “Manager Return code: ” & ReturnMsg
   
   If ReturnMsg <> “-125” Then
    Session.Property(“ExitInstSilent”) = “1”
    WriteMessageToMsiLog “Deployment Manager failed to copy files. We will interrupt the parent msiexec thread.”
   Else
    WriteMessageToMsiLog “Deployment Manager copied files successfully.”
   End If
   
   If fso.FileExists(InstallWorkflow_MSI_Path) Then
    fso.DeleteFile(InstallWorkflow_MSI_Path)
    WriteMessageToMsiLog “File deleted: ” & InstallWorkflow_MSI_Path
   End If
   
  Else

   Session.Property(“ExitInstSilent”) = “1”
   WriteMessageToMsiLog RDMCPath & ” is not found or does not exist. We will interrupt the parent msiexec thread.” 
  
  End if

  WriteMessageToMsiLog “Custom Action [Trigger_Inst_EMC_Silent] reached the end successfully.”

End Sub

‘—————————————————————————————————-
Sub Trigger_Inst_EMC_Silent_Patch()

  SourceDir = Session.Property(“SourceDir”)
  InstallDir = Session.Property(“INSTALLDIR”)
  RdeDefineFolder = Session.Property(“RdeDefineFolder”)
  
  PatchVersion = Session.Property(“APPLYPATCH”)
  PatchVersion = Replace(PatchVersion,”.”,”_”)
    
  WriteMessageToMsiLog “SourceDir : ” & SourceDir
  WriteMessageToMsiLog “InstallDir : ” & InstallDir

  WriteMessageToMsiLog “PatchVersion : ” & PatchVersion
  
  Set fso = CreateObject(“Scripting.FileSystemObject”)
  
  SourceDir = fso.GetParentFolderName(SourceDir)
  
  ProgramPath = fso.BuildPath(InstallDir, “\Program\”)
  RDMCPath = fso.BuildPath(ProgramPath, “RDMC.exe”)
  
  If fso.FileExists(RDMCPath) Then
   
   WriteMessageToMsiLog RDMCPath & ” exist.”
   Set ws = CreateObject(“WScript.Shell”)
   
   ‘Create the new InstallWorkflow_MSI.xml
   
   InstallWorkflow_MSI_Name = “InstallWorkflow_MSI_” & PatchVersion & “.xml”
   TempDir = ws.ExpandEnvironmentStrings(“%temp%”)
   InstallWorkflow_MSI_Path = fso.BuildPath(TempDir, InstallWorkflow_MSI_Name)
   
   Set InstallWorkflow_MSI_File = fso.CreateTextFile(InstallWorkflow_MSI_Path, True)
   InstallWorkflow_MSI_File.WriteLine(“<?xml version=””1.0″”?>”) 
   InstallWorkflow_MSI_File.WriteLine(“<install>”) 
   InstallWorkflow_MSI_File.WriteLine(“<copy source=”””& SourceDir &”\Files”” target=””[INSTALLDIR]””/>”)
   InstallWorkflow_MSI_File.WriteLine(“<patch/>”)
   InstallWorkflow_MSI_File.WriteLine(“<switch/>”) 
   InstallWorkflow_MSI_File.WriteLine(“</install>”) 
   InstallWorkflow_MSI_File.Close
   
   WriteMessageToMsiLog “Create ” & InstallWorkflow_MSI_Path
     
   rdmcCmd = “””” & ProgramPath + “rdmc.exe”” _silentMode=1 _execute=COPY_PATCH_FILES _InstallWorkflow=””” & InstallWorkflow_MSI_Path & “”” _scriptLogLevel=5 _logFilePath=””” & RdeDefineFolder & “TRD 6\Logs\”””
   
   WriteMessageToMsiLog “Run command: ” & rdmcCmd

   ReturnMsg = ws.Run (rdmcCmd,0,True)
   
   WriteMessageToMsiLog “Finish command: ” & rdmcCmd
   WriteMessageToMsiLog “Manager Return code: ” & ReturnMsg
   
   If ReturnMsg <> “10” Then
    Session.Property(“ExitInstSilent”) = “1”
    WriteMessageToMsiLog “Deployment Manager failed to copy files. We will interrupt the parent msiexec thread.”

    If fso.FileExists(InstallWorkflow_MSI_Path) Then
     fso.DeleteFile(InstallWorkflow_MSI_Path)
     WriteMessageToMsiLog “File deleted: ” & InstallWorkflow_MSI_Path
    End If
   End If
   
  Else

   Session.Property(“ExitInstSilent”) = “1”
   WriteMessageToMsiLog RDMCPath & ” is not found or does not exist. We will interrupt the parent msiexec thread.” 
  
  End if

  WriteMessageToMsiLog “Custom Action [Trigger_Inst_EMC_Silent] reached the end successfully.”

End Sub

‘—————————————————————————————————-

Function Exit_Inst_Silent()

    Const IDABORT = 3
 WriteMessageToMsiLog “Exiting with failure, this is done on purpose after calling Deployment Manager.”
 WriteMessageToMsiLog “Custom Action [Exit_Inst_Silent] reached the end successfully.”
    ‘Exit_Inst_Silent = IDABORT

End Function

‘———————————————————————————————————–

Sub WriteMessageToMsiLog(showLog)

 Dim oLogMessageRecord

 Set oLogMessageRecord = Installer.CreateRecord(1)
 oLogMessageRecord.StringData(1) = “[” + CStr(Date) + “-” + CStr(Time) + “]: ” + showLog
 Session.Message &H04000000, oLogMessageRecord

End Sub

 

Leave a Comment

You comments make us improve. So, please comment