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

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.

Related

SelfDel function removes uninstaller but is not removing app directory with 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.

Folder in start menu/installation folder still exists,After uninstallation using NSIS script?

I have written nsis script for Java project.once i have clicked uninstaller.exe
Start menu >all programs >my application
all the files are removed successfully from location of installed.but the problem is, folder in STARTMENU/installation folder still exists,after clicking uninstallation.I dont know why this happened? I have used windows 7.
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
I have used above code.Can anyone help me?
Where is the code to remove the directory? RMDir "$SMPROGRAMS\$StartMenuGroup"
It is also important to use RequestExecutionLevel so you don't run into compatibility issues...

NSIS - Install path problems

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

How to uninstall previous version silently using NSIS script?

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...

My NSIS script's Uninstall isn't deleting links from ProgramData directory

Got another newbie NSIS question. Here's the script:
; -*-nsis-*-
Name "ndhtest"
OutFile "FooStartMenuTest.exe"
XPStyle on
!define FOO_SRC c:\users\nhughes\foo
InstallDir "$PROGRAMFILES\Initech\"
Icon ${FOO_SRC}\foo_logo.ico
UninstallIcon ${FOO_SRC}\uninstall.ico
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
Section
SetOutPath $INSTDIR
File ${FOO_SRC}\foo.bat
WriteUninstaller "$INSTDIR\uninstall.exe"
CreateDirectory $SMPROGRAMS\Initech
CreateShortCut $SMPROGRAMS\Initech\Foo.lnk $INSTDIR\foo.bat "" \
"${FOO_SRC}\foo_logo.ico"
CreateShortCut $SMPROGRAMS\Initech\Uninstall.lnk $INSTDIR\uninstall.exe "" \
"${FOO_SRC}\uninstall.ico"
SectionEnd
Section "Uninstall"
Delete $SMPROGRAMS\Initech\Foo.lnk
Delete $SMPROGRAMS\Initech\Uninstall.lnk
RMDir $SMPROGRAMS\Initech
Delete $INSTDIR\Foo.bat
Delete $INSTDIR\uninstall.exe
RMDir $INSTDIR
SectionEnd
The uninstall seems to work except for leaving the shortcuts under ProgramData:
Directory of c:\ProgramData\Microsoft\Windows\Start Menu\Programs\Initech
08/10/2011 04:07 PM <DIR> .
08/10/2011 04:07 PM <DIR> ..
08/10/2011 04:23 PM 1,847 Foo.lnk
08/10/2011 04:23 PM 1,885 Uninstall.lnk
2 File(s) 3,732 bytes
2 Dir(s) 1,387,345,117,184 bytes free
What is my script getting wrong that is leaving this stuff hanging around?
Here is what the uninstaller writes to its console (I added a DetailPrint message listing $SMPROGRAMS):
smprograms=C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Remove folder: C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Initech\
Delete file: C:\Program Files (x86)\Initech\foo.bat
Delete file: C:\Program Files (x86)\Initech\uninstall.exe
Remove folder: C:\Program Files (x86)\Initech\
Completed
So the links under ProgramData never get referred to, it's looking for the links under AppData\Roaming instead.
I'm testing this on Windows 7, but the core problem here is I would like to be able to write a script that works on everything from XP to Windows 7, regardless of all the changes in how Windows squirrels away stuff in different spots in different versions. This is looking like it might be painful.
If DetailPrint is added to the nsis script, it starts to be apparent that NSIS tries to create the files under C:\Users, but they are actually created in c:\ProgramData. This ProgramData directory is a strange thing, because it's not visible with dir C:\, however it's possible to enter the directory with cd. Such mysteries are caused by Virtual Store, a tricky feature of Windows 7.
Now to the solution. Windows applications should define their execution level, otherwise system may behave in an unexpected way. You remember some applications ask whether to install "for current user only" or "for all users"? That's the thing we need to declare.
If we insert nsis instruction RequestExecutionLevel user, then the shortcuts are made for current user. If we do RequestExecutionLevel admin, then we should also add SetShellVarContext all to both install and uninstall sections.
This answer is based on the article from nsis wiki: Shortcuts removal fails on Windows Vista, where examples are given for both approaches.
From the spec:
4.9.1.8 RMDir
[/r] [/REBOOTOK] directory_name
Remove the specified directory (fully qualified path with no wildcards). Without /r, the directory will only be removed if it is completely empty. If /r is specified, the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, any file or directory which could not have been removed during the process will be removed on reboot -- if any file or directory will be removed on a reboot, the reboot flag will be set. The error flag is set if any file or directory cannot be removed.
Try adding the /r to the RMDir lines to force it to flush the contents. Either that or remove the links individually.

Resources