I am writing an uninstaller for my application, and I need to check from which directory uninstaller is invoked (because I want to restrict uninstallation from any other directory).
I am using built-in variable $EXEPATH
but it is giving me C:\Users\MyUser\Local\Temp\~nsu.tmp
instead of current directory.
I also used windows API GetModuleFileName
using nsis, but it is also giving same output. How to get the current directory for the executable?
The temporary directory in the form of
C:\Users\MyUser\Local\Temp\~nsu.tmp
is probably the directory where the uninstaller is actually running.To avoid problems with impossibility to remove the uninstaller executable because it is locked while running (so it need a reboot to be actually deleted), it is common to copy the uninstaller .exe to a temporary place and run it from there.
If you do not want the unistaller to fork itself into a temp directory, you can invoke it this way:
The trick involves the
_?
special parameter described in the manual.