Search code examples
nsis

NSIS $AppData pointing to a different folder on uninstall. Hot to fix it?


In my installer script I have:

Section "Installer Section" SecInstaller
    LogSet on

    ...

    LogText "$APPDATA\MyDir"
    SetOutPath "$APPDATA\MyDir"
    File "SolutionTree.lic"

    ...

    LogText "Installation complete."
SectionEnd

and the relevant part of the log:

... 
C:\Users\{user}\AppData\Roaming\MyDir
CreateDirectory: "C:\Users\{user}\AppData\Roaming\MyDir" (1)
...

Meanwhile on the uninstaller I have:

Section "Uninstall" SecUninstaller
    LogSet on

    ...

    LogText "Deleting $APPDATA\MyDir\MyFile.txt"
    Delete "$APPDATA\MyDir\MyFile.txt"

    ...

SectionEnd

and the relevant part of the log:

...
Deleting C:\ProgramData\MyDir\MyFile.txt
Delete: "C:\ProgramData\MyDir\MyFile.txt"
...

If I'm using $APPDATA in both the installer (an in the installer it points to the correct folder) why on the uninstaller it points to the wrong folder?


Solution

  • You are calling SetShellVarContext All in the uninstaller, this gives you the Machine/Common/All users version of $AppData.

    You should try to use the same SetShellVarContext context in both the installer and uninstaller. If you are using RequestExecutionLevel Highest and supporting both per-user and machine installs, you need to save the state of the context somewhere so you can restore it in the uninstaller.

    If you just need the user version of $AppData and don't care what the context is, use $UserAppData...