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 @ 2011-01-10 11:21  把爱延续  阅读(5069)  评论(0编辑  收藏  举报