The script's first WaitforApp starts X.exe. X.exe apparently checks to see what resolution is supported and runs X_(1024 x 768).exe and terminates itself. Watching the threads execute initially shows:

DaemonScript.exe
Daemonscript
X.exe
X_(1024 x 768).exe

However, the threads then change to:

DaemonScript.exe
Daemonscript
X_(1024 x 768).exe

Note that X_(1024 x 768).exe is no longer a sub of the script.

I have tried WaitforApp to terminate x.exe, X_(1024 x 768).exe and neither allows the following Unmount to execute i.e. the wait goes on and on even thought the threads running no longer shows X_(1024 x 768).exe as running:

DaemonScript.exe
Daemonscript

Yet the script sits there waiting.

Any suggestions of how to recognize that X_(1024 x 768).exe is no longer running so the WaitforApp will finish and the following Unmount will occur. Timeout wouldn't work since there's no set time for X_(1024 x 768).exe to be in use.