SelfDel function removes uninstaller but is not removing app directory with NSIS - nsis

In order to sign both the installer and uninstaller, I have created a separate uninstaller script as suggested here: https://nsis-dev.github.io/NSIS-Forums/html/t-245688.html. Thus, the uninstaller script not using the WriteUninstaller way to create the uninstaller.
Please note that I am using the SelfDel plug-in to delete the uninstaller, which works successfully; however, it does not actually delete the application install directory even though I am using the /RMDIR option:
Function .onInstSuccess
;SelfDel::Del /REBOOT
;SelfDel::Del /SHUTDOWN
SelfDel::Del /RMDIR
SelfDel::Del
SetAutoClose true
FunctionEnd
Here is the full script for your reference.
!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 $0\config.dat
Delete $0\MyApp.exe
Delete $0\ReleaseNotes.txt
Delete $0\MyApp_LandingPage_114.bmp
Delete $0\MyAppLicense.txt
Delete "$SMPROGRAMS\MyApp.lnk"
DeleteRegKey HKCU "SOFTWARE\${PRODUCT_NAME}"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd
Function .onInstSuccess
;SelfDel::Del /REBOOT
;SelfDel::Del /SHUTDOWN
SelfDel::Del /RMDIR
SelfDel::Del
SetAutoClose true
FunctionEnd
Does anyone have any suggestions on how to get it to delete the app directory? TIA.

So I don't really know the SelfDel nsis plugin that well, but have you tried just restarting your machine after deleting your install-directory like so?
SelfDel::Del /RMDIR
SelfDel::Del
SelfDel::Del /REBOOT
;or just
Reboot
That might help.
Wish you all the best.
Update
Ok so you tried to Reboot.
I researched a little further on the topic and found the same problem, but without the SelfDel plugin: How to solve "The directory is not empty" error when running rmdir command in a batch script?
But maybe you could also try to remove the directory and all the files in the "normal NSIS way" like this:
RMDir /r $YOURDIR
Try this maybe it will work, and perhaps it's just some bug from the plugin.
The SourceForge site of the plugin says it's only testet on Windows 8, so if you are using it on Windows 10 there might be some bugs.
Read the note at the bottom of the SourceForge site: https://nsis.sourceforge.io/SelfDel_plug-in
They say that it is a Trojan Virus and I would recommend to stop using it.
I would seriously consider using another plugin that is testet for Windows 10.
Wish you all the best.

Related

How to wait for parent NSIS Installer to be finished, before executing the embedded installer?

I am trying to run an installer inside the Script of another installer.
The parent installer needs to be finished to run the embedded installer inside properly.
!include "MUI2.nsh"
Icon "C:\Users\user\Pictures\logo.ico"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
ExecWait "$INSTDIR/CM/CMInstaller.exe"
SectionEnd
So how do I wait for the parent installer before executing the CMInstaller.exe?
Thanks for answering!
EDIT:
As Anders pointed out, the -POST is not a specific section name, just place this section (containing your child installer) after the main install section, or use .onInstSuccess callback function
Original answer:
In our project, we use -Post section to do some post-installation operations like placing the uninstaller or shortcut on the desktop, which might not be the best practice because there's a -FinishComponents section for the specified situation, check here
Section -Post
SetShellVarContext all
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\Uninst.exe"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\Uninst.exe"
;Write install path registry
WriteRegStr HKLM "${PRODUCT_INSTALL_DIR_REGKEY}" "${PRODUCT_INSTALL_DIR_SUBKEY}" $INSTDIR
!insertmacro WriteInstallLog "Install_log.log" "Installation completed"
;Execute CMInstaller here
ExecWait "$INSTDIR/CM/CMInstaller.exe"
SectionEnd
And according to the NSIS documentation, there's also a callback function .onInstSuccess when the installation is done successfully

When installing the same version of the windows installer software second time instead of silently installing it is showing the error message

I installed the windows installer software first time and it was installed properly.
If I manually uninstall the software from control panel->Add/Remove Programs then it is installing without showing any error message.
In the Section "Uninstall", I wrote the below code
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Test"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Test\EMR"
DeleteRegKey HKLM "SOFTWARE\Test\EMR"
DeleteRegKey HKLM "SOFTWARE\Test"
; Remove files and uninstaller
Delete $INSTDIR\EMR_4.0.1.nsi
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$INSTDIR\Test\EMR\*.*"
; Remove directories used
RMDir "$INSTDIR\Test\EMR"
RMDir "$INSTDIR\Test"
RMDir "$INSTDIR"
RMDir /r /REBOOTOK $INSTDIR
SectionEnd
Please help me to resolve the error.
It is hard to tell what is really going on based on your description but it is most likely one of two things:
The file is in use (open in another program or the program/service itself is running).
or
You don't have write access to that file. Make sure the installer is UAC elevated by setting the RequestExecutionLevel attribute.

Run application after install(silent installer)

I want to run my application immediately after install and I understand the code to do it is as follows:
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH
Section
CreateShortcut "$DESKTOP\HelloWorldShortcut.lnk" "$INSTDIR\Hello World.exe" "dev03 3"
SectionEnd
Function LaunchLink
ExecShell "" "$DESKTOP\HelloWorldShortcut.lnk"
FunctionEnd
The problem is my installer is a silent installer but the above code adds a page to it.
Is there a way to use a silent installer to also run the application immediately after install?
A silent installer can just run the app as the final step in the last section. Whether or not it is a good idea for a silent installer to start the application is something you should think about, personally I would say no...
Section
SetOutPath $InstDir
File "MyApp.exe"
...
IfSilent "" +2 ; If the installer is always silent then you don't need this check
ExecShell "" "$InstDir\MyApp.exe"
SectionEnd

Embedding other installers using NSIS

I an new to NSIS scripting. I want to create a custom installer which would wrap around another installer(FEKO). This method Embedding other installers suggested on the NSIS website did not work for me
The script compiles correctly but the embedded application is not installed. Here is the script
!include "MUI2.nsh"
!include "logiclib.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
#Name of the application we are trying to install
Name "FEKO"
# update this section to add 'contact' info
BrandingText "Please contact support at xyz#abc.com for any issues. "
# define the name of installer
OutFile "Custom_FEKO_6.2_Installer.exe"
# define default installation directory
InstallDir "C:\FEKO\6.2\"
DirText "Choose a directory where you want to install FEKO"
# start default section
Section "FEKO Installation"
# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
DetailPrint "Extracting FEKO Files into Installation Directory"
# specify files to go into the installation directory path
File /r "C:\Feko_Installer\*"
# set the current working directory
SetOutPath "$INSTDIR"
SectionEnd
Section "FEKO installation" FEKO
DetailPrint "Installing Feko"
# run the FEKO installer and wait for it to finish
File "C:\Feko_Installer\feko_distrib_6.2_win64.exe"
ExecWait "$INSTDIR\feko_distrib_6.2_win64.exe"
DetailPrint "Finishing up Installation"
SectionEnd
If the child installer needs admin privileges you need to put RequestExecutionLevel admin in your script. ExecWait (CreateProcess) fails if the exe has a manifest requesting elevation.
Correct quoting for ExecWait is: ExecWait '"c:\full\path\to\app.exe" /param1 "par am 2" /param3'

NSIS uninstaller - App Name missing (set dynamically)

I created an NSIS installer where the name of the app is taken from an .INI file (it has to be so since it will be used for multiple apps).
Name $APP_NAME
....
Function .onInit
ReadINIStr $R3 ${TECHPUB_INI_FILE} "General" "Installer_name"
StrCpy $APP_NAME $R3
....
FunctionEnd
....
Section install
....
WriteUninstaller $INSTDIR\Uninstall.exe
....
SectionEnd
The app name is correctly shown on the installer and it's the one from the .INI file. When I uninstall the app, the name is missing.
http://i48.tinypic.com/1934w9.png
Everything else works (uninstall removes all it has to remove). Any idea how to fix this?
Thank you!
The init function of the uninstaller is a separate un.onInit function. See Uninstall Callbacks.

Resources