NSIS:如何在nsis脚本中删除文件匹配的wildcat模式(NSIS: How to delete file matching wildcat pattern in nsis script)

编程入门 行业动态 更新时间:2024-10-08 23:02:27
NSIS:如何在nsis脚本中删除文件匹配的wildcat模式(NSIS: How to delete file matching wildcat pattern in nsis script)

当用户安装我的软件时,它会在用户的桌面上创建快捷方式。 快捷方式的名称也反映了正在安装的版本。

事实证明,我的一些客户端确实安装了多个版本(虽然这没有问题,没有冲突或其他什么),但这意味着用户的桌面充满了许多快捷方式,这些快捷方式随着时间的推移而安装了多个不同的版本。 (例如, SchoolServer 7.2.lnk SchoolServer 7.1.lnk , SchoolServer 7.2.lnk , SchoolServer 8.5.lnk ,然后是当前的SchoolServer 9.0.lnk )

他们必须手动删除这些过时的快捷方式。

如何在我的NSIS脚本中实现这一点?

注意:我尝试使用wildcat删除桌面上的所有版本的快捷方式,然后为已安装的版本创建快捷方式,但它创建了新的快捷方式,并且仍然保留旧的快捷方式。 我使用的代码如下:

;first delete stale shortcuts matching the wildcat Delete "$DESKTOP\SchoolServer *.lnk" ;create the new shortcut CreateDirectory "$INSTDIR" CreateShortCut "${ICON_URL}" "$INSTDIR\SchoolServer.exe" "" "" "" SW_SHOWMAXIMIZED ALT|CONTROL|SHIFT|F5 "SchoolServer"

When users install my software, it creates shortcut on the user's desktop. The name of the shortcut also reflects the version being installed.

It turns out that some of my clients do install multiple versions (although that is no problem, no conflicts or whatever) but it means that user's desktop is bloated with lots of shortcuts for the several various different versions that they have installed over time. (e.g. SchoolServer 7.1.lnk, SchoolServer 7.2.lnk, SchoolServer 8.5.lnk and then the current SchoolServer 9.0.lnk)

They have to be deleting these obsolete shortcuts manually.

How can I achieve this in my NSIS script?

Note: I have tried deleting the shortcuts on the desktop with wildcat for all versions and then create the shortcut for the installed version, but it created the new shortcut and still left the old shortcuts there. Code I used is below:

;first delete stale shortcuts matching the wildcat Delete "$DESKTOP\SchoolServer *.lnk" ;create the new shortcut CreateDirectory "$INSTDIR" CreateShortCut "${ICON_URL}" "$INSTDIR\SchoolServer.exe" "" "" "" SW_SHOWMAXIMIZED ALT|CONTROL|SHIFT|F5 "SchoolServer"

最满意答案

在删除之前使用SetShellVarContext切换到当前用户:

SetShellVarContext current Delete "$DESKTOP\SchoolServer *.lnk" SetShellVarContext all

Use SetShellVarContext prior to deleting, to switch to the current user:

SetShellVarContext current Delete "$DESKTOP\SchoolServer *.lnk" SetShellVarContext all

更多推荐

本文发布于:2023-08-03 19:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   模式   文件   如何在   NSIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!