SelfDel函数删除卸载程序,但不删除应用程序目录与NSIS



为了对安装程序和卸载程序都进行签名,我创建了一个单独的卸载脚本,如下所示:https://nsis-dev.github.io/NSIS-Forums/html/t-245688.html。因此,卸载脚本不使用WriteUninstaller的方式来创建卸载程序。

请注意,我正在使用SelfDel插件来删除卸载程序,它工作成功;但是,它实际上并没有删除应用程序安装目录,即使我使用/RMDIR选项:

Function .onInstSuccess

;SelfDel::Del /REBOOT
;SelfDel::Del /SHUTDOWN
SelfDel::Del /RMDIR
SelfDel::Del

SetAutoClose true
FunctionEnd

这是完整的脚本供您参考。

!define APP_COPYRIGHT "MyApp © MyCompany 2021"
!define COMPANY_NAME "MyCompany"         
!define LANG_ENGLSH "English" 
!define PRODUCT_NAME "MyApp"
!define PRODUCT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${BUILD_VERSION}"
!define SETUP_NAME "uninstaller.exe"
# define the name of the installer
OutFile ${SETUP_NAME}
Icon "favicon.ico"
!define MUI_ICON "favicon.ico"
# define the directory to install to
InstallDir "$PROGRAMFILES64${PRODUCT_NAME}"

# default section
Section

# define the output path for this file
SetOutPath $INSTDIR

# now delete installed files and registry keys for MyApp
ReadRegStr $0 HKCU "SOFTWARE${PRODUCT_NAME}" "InstallLocation"
DeleteRegKey HKCU "SOFTWARE${PRODUCT_NAME}"
Delete $0config.dat
Delete $0MyApp.exe
Delete $0ReleaseNotes.txt
Delete $0MyApp_LandingPage_114.bmp
Delete $0MyAppLicense.txt
Delete "$SMPROGRAMSMyApp.lnk"
DeleteRegKey HKCU "SOFTWARE${PRODUCT_NAME}"
DeleteRegKey HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstall${PRODUCT_NAME}"
DeleteRegKey /ifempty HKCU "SoftwareModern UI Test"   
SectionEnd
Function .onInstSuccess

;SelfDel::Del /REBOOT
;SelfDel::Del /SHUTDOWN
SelfDel::Del /RMDIR
SelfDel::Del

SetAutoClose true
FunctionEnd

有没有人对如何让它删除应用程序目录有任何建议?TIA。

所以我真的不知道SelfDel nsis插件那么好,但是你有没有尝试过在删除安装目录后重新启动你的机器?

SelfDel::Del /RMDIR
SelfDel::Del
SelfDel::Del /REBOOT
;or just
Reboot

那可能有帮助。

祝你一切顺利。

好的,所以你尝试重新启动。

我进一步研究了这个话题,发现了同样的问题,但没有SelfDel插件:如何解决"目录不空"在批处理脚本中运行rmdir命令时出错?

但是也许你也可以尝试用"正常的NSIS方式"删除目录和所有文件。这样的:

RMDir /r $YOURDIR

试试这个,也许它会工作,也许这只是插件的一些错误。

这个插件的SourceForge网站说它只在Windows 8上测试,所以如果你在Windows 10上使用它,可能会有一些错误。

阅读SourceForge网站底部的注释:https://nsis.sourceforge.io/SelfDel_plug-in他们说这是一个木马病毒,我建议停止使用它。

我会认真考虑使用另一个插件,是Windows 10的testet。

祝你一切顺利。