Archive: Need a Wait statement...?


Need a Wait statement...?
This must be a very common situation, so forgive me. I have a function that tests if the application being installed is already running:

FindWindow $0 "ThunderRT6FormDC" "TaskTracker"
IsWindow $0 0 done
Messagebox MB_OK|MB_ICONSTOP "Please exit TaskTracker before proceeding."
Abort

The problem is I don't want to Abort. I want to Wait till the user closes the running app. How can I do this?


Will a loop help you?

loop:
FindWindow $0 "ThunderRT6FormDC" "TaskTracker"
IsWindow $0 0 done
Messagebox MB_OK|MB_ICONSTOP "Please exit TaskTracker before proceeding."
Goto loop
done:


If that worked the way I expected, wouldn't it just show the message again the moment it was dismissed until the app was closed? (However, for some reason, it doesn't do that - it still terminates.) But anyway, what I would want to happen is to go back one page to Choose Install Location and not have the message reappear unless the user clicked Install again.


You can use NSIS Sleep in the loop.

Another way - WaitForSingleObject and other Win API calls with System plugin - VB sample from http://support.microsoft.com/default...b;EN-US;176391 below:

hWindow = FindWindow(vbNullString, "Calculator")
hThread = GetWindowThreadProcessId(hWindow, lProcessId)
hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
lngResult = WaitForSingleObject(hProcess, INFINITE)

If you don't want to send wm_close - modify this code to NSIS script, add MessageBox, loop, change INFINITE and so on...


Oh, I was thinking the MessageBox would tell them to close the other window. Then they would close it and click OK on the install message which would then retest and see that the window was closed and allow them to continue.
It sounds like what you should do now is make that function get hit when the user leaves that dialog and then stay on that dialog if the user still has that window open and display the message. Look up Page or Modern UI about leave functions. Abort is what you want in that case. Or attach your script and I can help you out.


OK, I tried the following:

!define MUI_DIRECTORYPAGE_VERIFYONLEAVE LeaveFunction
. . .
Function LeaveFunction

FindWindow $0 "ThunderRT6FormDC" "TaskTracker"
IsWindow $0 0 done
Messagebox MB_OK|MB_ICONSTOP "Please exit TaskTracker before proceeding."
Abort
done:

FunctionEnd

...and I get a compile warning:
1 warning:
install function "LeaveFunction" not referenced - zeroing code (306-311) out.

Thanks for your offer... here is my attached script.


Looks like it's not picking it up. Put the !define line just above the !insertmacro for the page you want to add the leave function for. I'm actually not sure where you wanted it so I just used MUI_PAGE_DIRECTORY in my example.

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "LeaveFunction"
!insertmacro MUI_PAGE_DIRECTORY


Thanks. That does exactly what I wanted. When Install is clicked, the message comes up, and when it's dismissed the installer state is unchanged.