vbscriptwindows-installerinstallshieldinstallshield-2009

InstallShield removing a file using VBScript & CustomAction fails when there's no file


When uninstalling a previous installation (that I'd built using InstallShield 2009), I wanted to delete the entire folder that the program was in at the end of the uninstall. I couldn't figure out how to do that using a Custom Aaction, so using the code below, I settled for deleting the file as soon as the installation starts. This works fine if the program was already installed... but if it wasn't installed before, it throws an error 1701 because, obviously, the folder didn't exist! I have no idea how to fix this issue and I know almost no VBScript. I started to do a try-catch to just gloss over the error, but apparently that doesn't exist in VBScript.

Dim fso, Folder2Delete
Folder2Delete =  "C:\Program Files\MyProgramDir"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder(Folder2Delete)

So either, How can I stick a Custom Action into an uninstall in InstallShield, or how can I set the VB script to only delete a file if it exists? Or last ditch, how can I get it to not show an error when it doesn't exist... ?

Thanks a lot, this is driving me crazy!


Solution

  • You can try this code:

    Dim fso, Folder2Delete
    Folder2Delete = Session.Property("CustomActionData")
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FolderExists(Folder2Delete) Then
      fso.DeleteFolder(Folder2Delete)
    End If
    

    For this custom action you can then set the action data (CustomActionData property) to:

    [INSTALLDIR]
    

    This way your action will delete whatever installation path your users set.