NSIS 打包 win7 中无法删除快捷方式

NSIS打包的安装程序,在Vista中的安装过程中如果向开始菜单添加了快捷方式的话,在卸载时卸载程序会不能正常删除这些快捷方式。

这 主要是因为Vista中使用UAC控制用户的权限。

我们使用NSIS打包程序一般会配套使用相应的脚本编辑器,比如HM NIS Edit,或者国内高手对HM NIS Edit进行源代码级增量改进之后的HM VNIS Edit,但是这两个软件都已经很久没有更新了,在使用向导创建开发脚本时,不会注意到使用Vista系统引起的问题,所以如果你使用上述两个脚本编辑器 生成脚本的话,就会出现这样的问题。

其实NSIS本身不存在什么问题,它提供了新的函数 RequestExecutionLevel语句(自2.21版添加),针对Vista的UAC进行权限请求,你只需在脚本中添加:

RequestExecutionLevel none|user|highest|admin

常 规安装程序只需user权限就可以解决上述问题了。

其他的解决方案:

使用SetShellVarContext all 将快捷方式创建到alluser的开始菜单中,但是感觉这样治标不治本。

参考自nsis官方文档:Shortcuts removal fails on Windows Vista

From NSIS Wiki

Windows Vista and Windows 7 automatically identifies installer executables, including NSIS installers, and asks the user permission to run them with elevated privileges. Automatic detection, however, comes with the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to All Users' Start Menu.

To workaround this, use the new RequestExecutionLevel command or create the shortcuts in All Users' folders in the first place, using SetShellVarContext.

复制代码
OutFile vista.exe
Name Vista

RequestExecutionLevel admin #NOTE: You still need to check user rights with UserInfo
!

Function .onInit
#TODO: call UserInfo plugin to make sure user
is admin
FunctionEnd

Section
SetShellVarContext all
CreateDirectory
"$SMPROGRAMS\Vista Test"
CreateShortcut
"$SMPROGRAMS\Vista Test\hello.lnk" $WINDIR\notepad.exe
WriteUninstaller $EXEDIR\uninst.exe
SectionEnd

Section uninstall
SetShellVarContext all
Delete
"$SMPROGRAMS\Vista Test\hello.lnk"
RMDir
"$SMPROGRAMS\Vista Test"
SectionEnd
复制代码

转载http://it.oyksoft.com/post/1522/

posted @   把爱延续  阅读(5092)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示