NSIS卸载后无法删除开始菜单中的内容

我们在安装程序时通常会使用createShortCut命令来创建一个快捷方式,如下,是在开始–>启动项 里创建run.bat的快捷方式。

CreateShortCut "$SMPROGRAMS启动 un.lnk" "$INSTDIRin un.bat"

当我们在执行卸载操作时是这样删除的,如下

Delete "$SMPROGRAMS启动 un.lnk"

但是,无论怎么样都删除不掉。

下面提供以下解决方案和为什么删不掉的原因:

原因:因为NSIS中使用CreateShortCut创建快捷方式时会在每一个人用户下面都创建快捷方式,然后Delete删的时候却只是在当前用户下,因此怎么删也删不掉。

解决方案:

1.在当前用户下创建快捷方式。只需添加RequestExecutionLevel user即可。

RequestExecutionLevel user   Section   CreateDirectory "$SMPROGRAMSVista Test"   CreateShortcut  "$SMPROGRAMSVista Testhello.lnk" $WINDIR
otepad.exe   WriteUninstaller $EXEDIRuninst.exe SectionEnd   Section uninstall   Delete "$SMPROGRAMSVista Testhello.lnk"   RMDir "$SMPROGRAMSVista Test" SectionEnd

2.删除所有用户下的快捷方式。首先添加RequestExecutionLevel admin,然后在创建快捷方式和删除快捷方式的地方加上SetShellVarContext all即可。

RequestExecutionLevel admin #NOTE: You still need to check user rights with UserInfo!   Section   SetShellVarContext all   CreateDirectory "$SMPROGRAMSVista Test"   CreateShortcut  "$SMPROGRAMSVista Testhello.lnk" $WINDIR
otepad.exe   WriteUninstaller $EXEDIRuninst.exe SectionEnd   Section uninstall   SetShellVarContext all   Delete "$SMPROGRAMSVista Testhello.lnk"   RMDir "$SMPROGRAMSVista Test" SectionEnd
原文地址:https://www.cnblogs.com/94cool/p/4256198.html