Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 10th March 2016, 20:03   #1
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
Help with getting installer/uninstaller to wait for an external program

I am trying to get my NSIS installer/uninstaller to wait for an external program called by the installer to complete. I have tried ExecWait as well as ExecDos and the ExecWaitJob macro, and whatever I try, the installer will not wait (or in the case of the ExecWaitJob macro either doesn't wait or freezes before calling the external program). I have tried directly running the executable I need to run, as well as running it via a batch file. With the batch file, I made sure to start the file with @Echo off, and end with cls per instructions in the wiki. I also tried dumping the EXE's output to a file, since it does print messags, and no luck. The main problem is on the uninstall, as files I need for the external program get deleted before the program can run. I suspect the external program is the culprit, but I can't modify it. Any suggestions to get around this with NSIS? Thanks.

The batch file is just:
@echo off
[program.exe]
cls

Or I've tried:
@echo off
start /wait [program.exe]. (both with and without /b switch)
cls
jwptrek is offline   Reply With Quote
Old 10th March 2016, 22:00   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
ExecWait always waits for the child process, when you say it does not wait then it means that this child process starts child processes of its own and ExecWait does not wait for those. First you should investigate if the thing you are running supports some type of command line parameter that makes it "waitable" and if it does not have one then the only solution is NT job objects.

Show me how you call the macro and I'll take a look this weekend...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th March 2016, 15:00   #3
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
I have tried using a cmd file as below:
ExecWait '"c:\program files\[company name]\usbdriver\uninst64.cmd"
as well as
ExecWait '"c:\program files\[company name]\usbdriver\wdreg.exe -inf file.inf -silent -delete_files uninstall"'

and what always happens is that the installer deletes the files before they can run even though the delete commands come after the ExecWait commands.

Because the program I am calling always prints out its version when it starts, I tried piping the output to a file (i.e. wdreg.exe ... >>file.txt, and that doesn't help either. I did find the source for that program, and even tried commenting out the print line in it, without luck. As far as I can tell from that program, it doesn't call any other programs. As I said before, I suspect that that particular program is the issue, as start /wait doesn't work with it either. I should note that the wdreg.exe program is a console mode application.

Unfortunately, the program does not have a wait option, either. To be honest, I am not sure what NT job objects are.

I've attached a copy of my cmd file, renamed with a .txt extension, as well as a copy of the nsi file with names redacted.

Thank you very much for your help.
Attached Files
File Type: nsi InstallUSB.nsi (6.5 KB, 146 views)
File Type: txt uninst64.txt (221 Bytes, 91 views)
jwptrek is offline   Reply With Quote
Old 12th March 2016, 16:58   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
ExecWait '"c:\program files\company name\usbdriver\wdreg.exe -inf usb64.inf -silent -delete_files uninstall"' has broken quotes, it should be ExecWait '"c:\program files\company name\usbdriver\wdreg.exe" -inf usb64.inf -silent -delete_files uninstall'.

I still need to see how you use ExecWaitJob if you want me to investigate that.

It might also be a good idea if you download Process Monitor and log the process and thread activity. Pressing Ctrl+T will show a process tree and you should be able to tell if there are any child processes that you are not waiting for.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th March 2016, 14:58   #5
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
I fixed the broken quotes per your instructions, and unfortunately, execwait is still not waiting. Below is how I tried to use ExecWaitJob. In my test, it appears that by the time wdreg.exe is even called, either via ExecWait or ExecWaitJob, the delete stuff below has already happened. I then get the message that wdreg couldn't be found.

StrCpy $8 'cmd /k start "" "c:\program files\[companyname]\usbdriver\uninst64.cmd"'
!insertmacro ExecWaitJob r8
jwptrek is offline   Reply With Quote
Old 15th March 2016, 02:40   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 853
What is r8 used for? If it's a variable, it should be $8.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 15th March 2016, 07:23   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
Quote:
Originally Posted by JasonFriday13 View Post
What is r8 used for? If it's a variable, it should be $8.
No r8 is correct because that macro is weird IIRC.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 6th April 2016, 15:55   #8
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
I also forgot to mention that I've called ExecWaitJob with the exe itself as in:
StrCpy $8 'cmd /k start "" "c:\program files\[company name]\usbdriver\wdreg.exe -inf file.inf -silent -delete_files uninstall"'
!insertmacro ExecWaitJob r8

Without luck as well. Any suggestions? Thanks.
jwptrek is offline   Reply With Quote
Old 7th April 2016, 00:52   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
I already told you that you need to use the double quotes correctly, you quote the filename/path but not the parameters. Also, you don't need cmd.exe to run another .exe!

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th April 2016, 17:10   #10
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
Actually, I tried it both with and without the call to cmd, and with the correct quotes without luck. I didn't check the quotes when I pasted it. I also tried calling my .cmd file, as below:

StrCpy $8 'cmd /k start "" "c:\program files\[companyname]\usbdriver\driveruninst64.cmd"'

without luck.

I did go back and try again with the correct quotes with ExecWaitjob, calling the executable, and it seems to work now. I thought I tried the current iteration, including options to the executable, with correct quotes before, but I must not have. See below:

StrCpy $8 'cmd /k start "c:\program files\[company name]\usbdriver\wdreg.exe" -inf usb64_drv.inf -silent -delete_files uninstall'
!insertmacro ExecWaitJob r8

I am just glad it appears to be fixed now. I'd have preferred calling my cmd file, as it hides things a bit better, but I will go with what works. Thanks for the help.
jwptrek is offline   Reply With Quote
Old 11th April 2016, 18:10   #11
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,590
I still don't understand why you insist on using cmd.exe to start a .exe and don't use /k, use /c if you must.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th April 2016, 18:19   #12
jwptrek
Junior Member
 
Join Date: Mar 2016
Posts: 6
Well, whatever the reason, the last two code lines I pasted *finally* actually wait, even though I shouldn't need the cmd /k in there. I just tried it again without the cmd, with the below code, and it works also.

StrCpy $8 '"c:\program files\[company name]\usbdriver\wdreg.exe" -inf usb64_drv.inf -silent -delete_files uninstall'
!insertmacro ExecWaitJob r8

I was sure I went back and tried ExecWaitJob with correct quotes before, but I must've either just tried with the .cmd file. In any case, it is finally working, so I'm happy. Thanks.
jwptrek is offline   Reply With Quote
Old 29th March 2017, 13:30   #13
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 142
Sorry for my stupid question, but I have some problems to convert this macro to a function. I don't understand completely why we copy the path to the variable $8 and then we give like a parameter to the macro R8 instead of $8. When I make a function based on this macro it doesn't work and I think that this is exactly because I done give the parameter correctly. Some help, please...
TrifonovS is offline   Reply With Quote
Old 29th March 2017, 13:59   #14
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 142
I solved my problem. I have to get the parameter with Pop $8, but in the lines that the value must be used I have to write:
System::Call 'kernel32::CreateProcess(i0,t r8,i0,i0,i0,i 0x01000004,i0,i0,i $4,i $0)i.r3'
It works now!
TrifonovS is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
execdos, execwait, nsis

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump