Skip to content
⌘ NSIS Forum Archive

Wait for a process to end I didn't start?

6 posts

MichaelFlya#edited

Wait for a process to end I didn't start?

Simple and short. How do I get the installer
to wait on a process to end I didn't start?

I need something like "ExecWait" for a process, yet the
process isn't executed by my installer. I need to pause
the installer without a messagebox until the process I
choose isn't running any longer. I keep coming across
a dead link within a recurring solution in threads posted
by Kichik. Here is a link to one of those threads below.

Thread:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Dead link:


-MichaelFlya-
Takhir#
For apps with window:

!macro TerminateApp

StrLen $5 "${PROG_NAME}"
IntOp $5 $5 + 1 ; terminating 0 for caption to compare

restart:
StrCpy $0 "0"

loop:
; FindWindow $0 '' '' 0 $0
FindWindow $0 'WindowsForms10.Window.8.app1' '' 0 $0
IntCmp $0 0 done
System::Call 'user32.dll::GetWindowText(i r0, t .r4, i r5) i .r2'
StrCmp $4 "${PROG_NAME}" 0 loop
System::Call 'user32.dll::GetWindowThreadProcessId(i r0, *i .r1)'
System::Call 'kernel32.dll::OpenProcess(i 0x00100000, i 0, i r1) i .r2'
SendMessage $0 0x0010 0 0 /TIMEOUT=2000
System::Call 'kernel32.dll::WaitForSingleObject(i r2, i 3000) i .r3'
IntCmp $3 0 done
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "Installer cannot terminate \
running ${APP_NAME}.$\nClose Application and re-run Installer." IDOK restart
Quit
done:

!macroend
MichaelFlya#
Ok I start up the process "notepad.exe" after
which I start up my installer and hit install.

Now if the code works correctly the installation
should pause with the loading bar not moving till
I close notepad. How do I insert this in the script
correctly and properly?

-MichaelFlya-
KenA#
Re: Wait for a process to end I didn't start?

Originally posted by MichaelFlya
Simple and short. How do I get the installer
to wait on a process to end I didn't start?

I need something like "ExecWait" for a process, yet the
process isn't executed by my installer. I need to pause
the installer without a messagebox until the process I
choose isn't running any longer. I keep coming across
a dead link within a recurring solution in threads posted
by Kichik. Here is a link to one of those threads below.

Thread:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Dead link:


-MichaelFlya-
Hi Michael,

for processes that don't include a window, you should use the FindProcDLL plug-ins - I never remember if all those plug-in I use are in the standard NSIS install, sorry - in a loop and exit the loop if the process is not found.

I'd also advise you to use a sleep instruction in your loop, or else you might peg the processor if your loop is tight. 🙂

KenA
Takhir#
Notepad window class name is 'Notepad' (for FindWindow).
For this specific window class you can skip 4 lines of window caption check out (2 lines at the beginning and GetWindowText+StrCmp in the loop). And " - Notepad" text is lang dependant and appears at the end of caption (like IE does). Please note 2000 and 3000 msec timeouts in the code. Usage:

!insertmacro TerminateApp
MichaelFlya#
Well, KenA has a good solution it seems.
Using the plugin found at this link:



Plus using the code below. Which did the trick.



Section "Test"
Loop:
FindProcDLL::FindProc "notepad.exe"
StrCmp $R0 0 0 +2
;MessageBox MB_OK "The number is $R0 meaning it is not found."
Goto Done
StrCmp $R0 1 0 +2
;MessageBox MB_OK "The number is $R0 meaning it is found."
Goto Loop
Done:
SectionEnd
Thanks !!


-MichaelFlya-