InstallShield 使用 VBScript 删除文件没有文件时 CustomAction 失败

发布于 2024-12-02 11:46:58 字数 542 浏览 1 评论 0原文

卸载以前的安装(我使用 InstallShield 2009 构建的)时,我想在卸载结束时删除该程序所在的整个文件夹。我不知道如何使用自定义操作来做到这一点,因此使用下面的代码,我决定在安装开始后立即删除该文件。如果该程序已安装,则效果很好...但如果之前未安装,则会抛出错误 1701,因为显然该文件夹不存在!我不知道如何解决这个问题,而且我几乎不懂 VBScript。我开始执行 try-catch 来掩盖错误,但显然 VBScript 中不存在这种情况。

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

那么,如何将自定义操作粘贴到 InstallShield 中的卸载中,或者如何将 VB 脚本设置为仅删除文件(如果存在)?或者最后一搏,当它不存在时我怎样才能让它不显示错误......?

非常感谢,这让我发疯!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

或十年 2024-12-09 11:46:58

您可以尝试以下代码:

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

对于此自定义操作,您可以将操作数据(CustomActionData 属性)设置为:

[INSTALLDIR]

这样您的操作将删除用户设置的任何安装路径。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文