I need to uninstall previous version if installed already. I have a NSIS script. Here is what I have tried:-
Function UninstallPreviousVersion
ReadRegStr $R0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
StrCmp $R0 "" done remove
remove:
DetailPrint "Removing previous installation."
ExecWait '"$INSTDIR\uninst.exe" /S _?=$INSTDIR'
done:
FunctionEnd
But When I run it instead of uninstalling old and install new version. it creates a new folder 'bin' under installation folder.
Any help please?
You might want to read the uninstall directory from the registry in case the old install location is not the same as $instdir but this is not your real problem. Your code does look correct so I suggest you do some "MessageBox debugging" in your uninstaller code...
Related
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.
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.
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.
I'm having some path problems in the default installation. My code below:
http://pastebin.com/7vrCuLiZ
And my problem is that the default path to install is "C:\Program Files (x86)\Advanlab\DISK1\Common\Borland Shared\BDE\" instead of "C:\Program Files (x86)\Advanlab"
https://www.dropbox.com/s/vfoxytj1sbvqs5a/helpnsis.png
Thanks for your help :)
EDIT:
It only happens if the folder Advanlab already exist :s
The InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" command is probably picking up this directory, try InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
Have you set the default installation directory in your NSIS script?
; The default installation directory
InstallDir $PROGRAMFILES\xxx
I have an NSIS installer that calls an uninstaller to automatically uninstall the older version of the program.
http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new
Unfortunately, there is the possibility for the user to click on the install, and run the installer before running the uninstall, then proceed with the uninstall...
Is there any way to force the installer in the background while the uninstall is active ?
Edit: tried to disable the "Install" button,
ClearErrors
;disable the Install button
GetDlgItem $R1 $HWNDPARENT 0
EnableWindow $R1 0
...
done:
;disable the Install button
GetDlgItem $R1 $HWNDPARENT 0
EnableWindow $R1 0
I keep disabling the "Close" button on the uninstaller instead. I thought that this section is still in the installer...
I don't see how there can be any UI displayed by .onInit that the user can click on since the main window has not been created yet but if you moved the code somewhere else you could Hide/Show the installer with HideWindow+BringToFront (Basically ShowWindow $HWNDPARENT 0|1) or disable the buttons you don't want the user to click on with GetDlgItem+EnableWindow.
Based on the code snippet you linked to I think that you have no need to worry.
The .onInit function is executed prior to the installer UI being drawn on the screen, hence the uninstaller is going to be run before the user even has a chance to interact with the installer.
Just to make sure you are correctly understanding what that code is doing, when you run the new installer it is looking in the Registry to find the location of the Uninstaller executable of the old version, then popping a message box asking if you would like to uninstall the previous version. If you click ok then it will execute the uninstaller using the ExecWait instruction which will prevent the next instruction from being executed until the uninstaller returns (finishes). If the user clicks cancel it will then skip the uninstall of the old version.
Because all of this is done in the .onInit function, the User has no chance to interact with the new version before the old version is uninstalled.
The only way they could install the new version prior to uninstalling the old version is if they click on cancel when the messagebox comes up. If you would like to remove this option then you could change the MessageBox code too:
MessageBox MB_OK|MB_ICONEXCLAMATION \
"${PROGRAM_NAME} is already installed. $\n$\nClick `OK` to remove the \
previous version"
You also need to remove the IDOK uninst and Abort lines following the MessageBox instruction.
Hope this helps.
The Basic format of your script should be:
Function .onInit
code you linked to goes here
FunctionEnd
Section "Install"
install stuff goes here
SectionEnd
Section "Uninstall"
Uninstall stuff goes here
SectionEnd
call Uninstaller as following.
ExecWait '"$INSTDIR\Uninstall.exe" _?=$INSTDIR'
Then use BringToFront
It will hide Installer until Uninstaller Exists.