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 am trying to install 7-Zip.msi using msiexec. Whilst I can execute the msi using the following nsis command it defaults installation to C:\Program Files
ExecWait '"msiexec" /passive /i "$OUTDIR\<msi filename>.msi"'
I cannot find a way of specifying a custom destination directory for the install.
msiexec documentation suggests I can use TARGETDIR. So I tried the below
SetOutPath "C:\Software\7-Zip"
DetailPrint "Installing 7-Zip to $OUTDIR"
ExecWait '"msiexec" /passive /i "$OUTDIR\7-Zip.msi" TARGETDIR="$OUTDIR"'
But when I run the nsis exe I get no error, but 7-Zip has not been installed to the C:\Software\7-Zip directory.
Does anyone know how you specify a target installation directory when using msiexec?
ExecWait '"msiexec" /passive /i "C:\Temp\7-Zip.msi" INSTALLDIR="$OUTDIR"'
Using INSTALLDIR solved the issue. Seems as though INSTALLDIR is a property specific to the 7-Zip.msi. Some msi files use TARGETDIR.
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...
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...
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.