- NSIS Discussion
- Uninstall Files from different location
Archive: Uninstall Files from different location
anandharaja
24th July 2011 07:11 UTC
Uninstall Files from different location
hi,
i want to create installer for my program, but i install the files in different location for example $PROGRAMFILES\My program1 and some files in $PROGRAMFILES\My program2 and so on. but the installer fail to uninstall files from different location.
if i write uninstaller in my Program1 folder means it uninstall all files in my program1, failes to uninstall files in other locations.
How can i create installer to uninstall all files.
MSG
24th July 2011 07:52 UTC
In the uninstaller the value of $INSTDIR is actually $EXEDIR. So while themost straight-forward way may seem to be just making two uninstallers, you'll run into the same problem when you're trying to execute the second one. :P
So what you need to do is save the exact path that you installed to, either in the uninstaller using FileWriteByte etc, or in the registry or an ini file.
anandharaja
24th July 2011 10:12 UTC
Thanks for the reply,
iam not write these type of installer before, can you provide example script.
Thanks.
MSG
24th July 2011 14:00 UTC
The manual has all the information you'll need. Simply use the INI commands to write the paths to an ini file. Then in un.onInit, read the paths from the INI file and you'll know what paths to delete your files from.
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2
LoRd_MuldeR
24th July 2011 14:33 UTC
If, during install, you ignore $INSTDIR (the install path selected by user) and instead install to some "fixed" paths, such as "$PROGRAMFILES\My program1" and "$PROGRAMFILES\My program2", then I think the uninstaller should also un-install (remove) files from the "fixed" paths "$PROGRAMFILES\My program1" and "$PROGRAMFILES\My program2". This won't work if the install folders were moved/renamed in the meantime, but in that case storing the original paths in some INI file or in the Registry doesn't help either...
MSG
24th July 2011 15:35 UTC
Of course, you should always verify that the path is correct. If for example it has the wrong files, then it's probably not safe to go deleting stuff...
LoRd_MuldeR
24th July 2011 16:27 UTC
Originally posted by MSG
Of course, you should always verify that the path is correct. If for example it has the wrong files, then it's probably not safe to go deleting stuff...
Sure. But my point was: He ignored the user-selected $INSTDIR and installed to a
fixed path, such as "$PROGRAMFILES\My program1" instead. Of course the path is not "fixed" in the sense that it will be identical on every computer (because of $PROGRAMFILES), but it
is fixed for a specific computer. So at un-install time it is safe to uninstall from the same fixed path that we installed to at install time. There is no need to remember a fixed path in an INI file or the Regsitry, because... well... it is fixed.
(Assuming that the suffix "My program1" is unique to his program, of course! Not something commonly used by another product. But if the suffix wasn't unique, then installing to fixed path "$PROGRAMFILES\<suffix>" wouldn't be safe, in the first place)
anandharaja
30th August 2011 09:21 UTC
Thanks to MSG and LoRd_MuldeR for your replies.
but i still in confusion, where to i use WriteINI Str in Section or i need to create Function.
please can you provide example script with two sections.
MSG
30th August 2011 11:51 UTC
I suggest you create a hidden final section in your installer: Section "-LastSection" LastSection
In that section you use the INI instructions to write the path of 'My program2' to an ini file in the 'my program1' directory. The uninstaller, also created in the 'my program1' directory, can read the ini file using ReadINIStr (you can do this in the Uninstall section, or in the un.onInit function).
I'm not going to write example code here, because it's extremely simple to do and it's a worthwhile exercise for you to figure it out on your own. Look at the INI command examples in the link I provided earlier, they'll show you how to use the commands.