How do I get the EXE path in an nsis script?

I am writing an uninstaller for my application and I need to check from which directory uninstaller is called (because I want to restrict deletion from any other directory).

I am using a built in variable $EXEPATH

but it gives me the C:\Users\MyUser\Local\Temp\~nsu.tmp

current directory instead.

I have also used the Windows API GetModuleFileName

using nsis, but also gives the same result. How do I get the current directory for the executable?

+3


source to share


1 answer


The temp directory in the form C:\Users\MyUser\Local\Temp\~nsu.tmp

is probably the directory where the uninstaller is actually running.

To avoid the problem of not being able to uninstall the uninstaller executable because it is locked while running (so a restart is required to actually uninstall it), you usually need to copy exinstaller.exe to a temporary location and run it from there.

If you don't want the unistaller to expand itself into the temp directory, you can invoke it like this:



ExecWait '"$INSTDIR\uninstaller.exe" /S _?=$INSTDIR'

      

The trick includes a special parameter _?

described in the manual .

0


source







All Articles