NSIS' uninstaller works very fast - nsis

I have no idea how to say it short for title, but
When I run uninstaller generated by NSIS in silent mode, it detaches from main process and do its work in the background.
This is good, but when installer run ExecWait uninstaller first, it finish instantly, but doesn't uninstall application actualy. As a result, installer tries to replace executable file that executed, but not closed by uninstaller yet. Any solution?

Ok, I got it.
The NSIS uninstaller copies itself to the temporary directory, runs the temporary uninstaller created and then exits. This is done so it will be able to delete itself.
You can disable this system using the following command line parameter:
ExecWait '"$INSTDIR\uninstall.exe" _?=$INSTDIR'
You will, of course, have to replace uninstall.exe with the name of your uninstaller.

Related

Delete command after execwait is not working

I'm creating one installer. I need VC++2013 runtime for my applicaiton. So i'm checking and if not found VC++ runtime i'm installing it from my installer.
To do that, I'm copying VC++ runtime exe into programfiles/myapplication and running it using
ExecWait '"$INSTDIR\vc.exe" /passive /norestart' $0
Delete "$INSTDIR\vc.exe"
But the problem is vc.exe is not getting deleted. It remains in programfiles/myapplication folder.
I use IfErrors command and found that error occurs.
Please suggest me how to solve this
ExecWait always waits until the child process ends but just because the process has ended does not mean you can delete the .EXE file. It should ideally mean that but in some cases Explorer or Anti-Virus will keep files locked for a couple of seconds. Without more information it is hard to say why it can't be deleted, Process Monitor will probably provide some clues.
You could try
ExecWait '"$INSTDIR\vc.exe" /passive /norestart' $0
Sleep 2500
Delete "$INSTDIR\vc.exe"
but since you are just going to delete it anyway, I would suggest extracting it somewhere else that NSIS will try to clean up for you instead:
Section
InitPluginsDir
File "/oname=$PLUGINSDIR\vc.exe" "c:\myredistfiles\vc.exe"
ExecWait '"$PLUGINSDIR\vc.exe" /passive /norestart' $0
SectionEnd

NSIS Installer Run Batch File

Trying to run a batch file at the end of an installation, everything works great except this file won't run.
section "Startup"
Exec '"$0" /C "C:\Program Files\placeholder\startup\startup.bat"'
sectionEnd
Everything gets deposited in the right spot, using absolute pathing to call this. I asked for administrator privileges at the start,
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
Just copying from the example NSIS installer provided here
The file is there so I must be making a mistake with the file path or missing some parameter. Been trying a lot of permutations like nsExec but not sure my mistake. Hopefully this is a simple mistake and will aid others in the same boat at some time.
Without more information I would guess that this is a 64-bit Windows machine and filesystem redirection is causing your 32-bit installer to access the wrong program files directory.
The code you posted is also problematic because we don't know what $0 is. I assume you failed to post the code where it expands %comspec%. To rule out this, replace $0 with $sysdir\cmd.exe.
Ideally your installer should extract the batch file to the destination directory:
Section
SetOutPath $InstDir
File batch.bat
ExecWait '"$sysdir\cmd.exe" /C if 1==1 "$InstDir\batch.bat"'
SectionEnd
If you must access the 64-bit folder you can disable the redirection but this is not recommended:
!include x64.nsh
Section
${DisableX64FSRedirection}
ExecWait ... $ProgramFiles64\...
${EnableX64FSRedirection}
SectionEnd
I think that you should give us more information to solve this problem.
Based on current information, I guess there are two reasons:
"C:\Program Files" is a path for 64-bit programs, but NSIS installer is a 32-bit program, so this path will be redirected to "C:\Program Files (x86)". You can use the solution from Anders to solve it.
Your batch file may contains relative paths. When you run your batch file from the NSIS installer, your working directory is not as same as your batch file. Due to this, some command cannot run correctly. You can use %~dp0 to solve it.

Customize or remove NSIS uninstaller prompt

Is there a way to customize (call a custom plugin) or even completely remove the NSIS uninstaller prompt Would you like to proceed with uninstall? by adding a directive or any other piece of magic to the NSIS script?
I have also tried passing either of the /q or /s to the uninstall.exe with no effect.
This is not a normal NSIS message, did you use a generator or template to create your script?
You should be able to find the MessageBox in your script source and remove it (Or set a default for silent mode)

Execute files which are generated while runtime

Still in progress with NSIS Setup.
The thing is now I´m executing NSIS executables during my "main" setup. Those other setups, which I´m executing, generate uninstaller for themselve. When I´m performing the uninstaller in the main setup I would like to call those generated uninstaller files.
I´m doing the execution with nsExec::ExecToLog but if a executable is not from the decompressed from the .exe you won´t be able to execute it. Am I right? Is there any solution to solve this problem?
I´m very grateful for every answer!
You can use nsExec::ExecToLog with whatever you like.
It could be extracted:
SetOutPath $INSTDIR
File foo.exe
nsExec::ExecToLog $INSTDIR\foo.exe
It could be a path already known:
nsExec::ExecToLog $WINDIR\bar.exe
It could be calculated:
ReadINIStr $0 $INSTDIR\uninstaller-paths.ini UninstallerPaths baz
nsExec::ExecToLog $0
It really doesn't matter. As far as the script is concerned, it's purely a command string to execute.

Is it possible to package an exe into an NSIS generated installer which runs first?

Is it possible to generate an NSIS installer (using a .nsi) which packages an exe (let's say foobar.exe) which is then run before the installer actually installs the program as normal? I assume it'd have to extract the exe to a temp dir before running it, which is fine. It must be run before the main install however.
Initpluginsdir
File "/oname=$pluginsdir\myapp.exe" "c:\build\myapp.exe"
ExecWait '"$pluginsdir\myapp.exe"'
Delete "$pluginsdir\myapp.exe" ;delete is optional, $pluginsdir is auto-deleted when installer quits
Put before other code in your first section or in .onInit (Depending on what myapp.exe does etc)

Resources