开发者

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

开发者 https://www.devze.com 2023-04-01 12:13 出处:网络
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 h

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 l开发者_开发技巧ast ditch, how can I get it to not show an error when it doesn't exist... ?

Thanks a lot, this is driving me crazy!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号