Archive: Uninstaller Determine Name of its Parent Folder


Uninstaller Determine Name of its Parent Folder
  This will probably be trivial for the gurus on this forum but I need some help because I'm a n00b to NSIS. Thanks in advance!

I need to have my uninstaller determine the name of the parent folder from which the uninstaller is being run.

For example, if the uninstaller is being run from "C:\Data\ProgramName\uninstall.exe", I need to store the string "ProgramName" for later use.

Ideas?


Oh, my...there's a perfect function GetParent in FileFunc.nsh .
The usage is described in NSIS help ;) .
And if you need to retrieve the folder name only, you can use GetFileName from the same header for the parent folder you previously got.
I'm sorry, i can't type a code 'cause i'm using mobile internet ATM :-S .
Good luck.


4.6.2 Uninstall Section
A special Section named 'Uninstall' must be created in order to generate an uninstaller. This section should remove all files, registry keys etc etc that were installed by the installer, from the system. Here is an example of a simple uninstall section:
Section "Uninstall"
Delete $INSTDIR\Uninst.exe ; delete self (see explanation below why this works)
Delete $INSTDIR\myApp.exe
RMDir $INSTDIR
DeleteRegKey HKLM SOFTWARE\myApp
SectionEnd
The first Delete instruction works (deleting the uninstaller), because the uninstaller is transparently copied to the system temporary directory for the uninstall.

Note that in uninstaller code, $INSTDIR contains the directory where the uninstaller lies. It does not necessarily contain the same value it contained in the installer.
If you need to store the installer directory, you can StrCpy $INSTDIR or WriteRegStr $INSTDIR.

Thanks for the replies!
I tried the GetParent function...

It takes "C:\Program Files\Directory\Whatever" and returns "C:\Program Files\Directory"

What I need is the opposite - to push "C:\Program Files\Directory\Whatever" and return "Whatever"

Being a n00b, I couldn't figure out how to modify GetParent to do the opposite - maybe someone on the forum would know how?



Section "Uninstall"

Push "C:\Program Files\Directory\Whatever"
Call un.GetParent
Pop $R0
;...more uninstall code here...
>SectionEnd

>Function un.GetParent

Exch $R0
Push $R1
Push $R2
Push $R3

StrCpy $R1 0
StrLen $R2 $R0

loop:
IntOp $R1 $R1 + 1
IntCmp $R1 $R2 get 0 get
StrCpy $R3 $R0 1-$R1
StrCmp $R3 "\" get
Goto loop

get:
StrCpy $R0 $R0 -$R1

Pop $R3
Pop $R2
Pop $R1
Exch $R0

FunctionEnd
>

Re: Uninstaller Determine Name of its Parent Folder
 

if the uninstaller is being run from "C:\Data\ProgramName\uninstall.exe", I need to store the string "ProgramName" for later use.
; example: running C:\Data\ProgramName\uninstall.exe
!include "FileFunc.nsh"
${GetFileName} "$INSTDIR" $0
; $0 is ProgramName

Thanks guys, that works great!