We have a licensed copy of Macro Scheduler here for commercial use, but we have some problems. I hope you can help us

Our Macro runs a program with some parameters.
A new Window opens. After this operation i will wait until the opened window is closed. I use " WaitWindowClosed " for this instruction.
in principle this macro runs perfect, but however it occurs frequently that the instruction "WaitWindowClosed" has been ignored and the next Step of Macro will be executed. Our Macro is partitioned in three steps. Each step runs a program (window opens) and the Macro is holded until this window is closed. If this condition is true, the next Step will runs and opens a new window. These windows have the same window title. The program needs to be opened the whole day. For this reason I must terminate and then start the program with parameters again.
We can only run Macros in this program about parameters in the commandline. We close the program and restart it with the macro parameters. But if the WaitWindowClosed step is ignored, we have two windows with the same name opened. Now the macro hangs until the second window is closed.
How can I avoid this problem?
I hope you can understand my problem definition.
Im from Germany... sorry for bad english

I would be pleased about your answers.
Macro:
// Navision Fenster bereits geöffnet ? Ansonsten starten
IfWindowOpen>C:\Navi\NAVIN.EXE,weiter
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=DV04,Temppath=c:\Navitemp\EDITemp
Wait>3
Label>weiter
Goto>Start
//Verschieben der orders.dat
Label>In
Let>quellein=d:\EDIalog\daten\appl\empf\orders.dat
Let>zielin=d:\x400\tmobil\in\
MoveFile>quellein,zielin
Wait>10
Goto>Macro1
//Ausführen von Navision Makro 1 [ M1 - Einlesung von orders.dat ]
Label>Macro1
CloseWindow>C:\Navi\NAVIN.EXE
Wait>1
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM1,Temppath=c:\Navitemp\EDITemp,macro=c:\navi\m1
Wait>2
Let>WW_TIMEOUT=180
WaitWindowClosed>C:\Navi\NAVIN.EXE
Wait>1
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM1,Temppath=c:\Navitemp\EDITemp
Wait>3
If>WW_RESULT=TRUE,Macro2
ScreenCapture>0,0,1024,768,P:\Error_M1.jpg
Goto>Error1
//Ausführen von Navision Makro 3 [ M3 - Stapel Aufträge anlegen ]
Label>Macro2
CloseWindow>C:\Navi\NAVIN.EXE
Wait>
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM2,Temppath=c:\Navitemp\EDITemp,macro=c:\navi\m3
Wait>2
Let>WW_TIMEOUT=180
WaitWindowClosed>C:\Navi\NAVIN.EXE
Wait>1
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM2,Temppath=c:\Navitemp\EDITemp
Wait>3
If>WW_RESULT=TRUE,Macro3
ScreenCapture>0,0,1024,768,P:\Error_M3.jpg
Goto>Error2
//Ausführen von Navision Makro 4 [ M4 - Packlisten drucken ]
Label>Macro3
CloseWindow>C:\Navi\NAVIN.EXE
Wait>1
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM4,Temppath=c:\Navitemp\EDITemp,macro=c:\navi\m4
Wait>3
Let>WW_TIMEOUT=180
WaitWindowClosed>C:\Navi\NAVIN.EXE
Wait>1
Run Program>C:\Navi\NAVIN.EXE serverno=1,ID=MacroM4,Temppath=c:\Navitemp\EDITemp
Wait>3
If>WW_RESULT=TRUE,End
ScreenCapture>0,0,1024,768,P:\Error_M4.jpg
Goto>Error3
//Archivierung der orders.dat
Label>DoArchiv
Let>pfadin=d:\x400\tmobil\in\
Let>pfadarchiv=F:\x400\In\Archiv\
Let>quelle=d:\x400\tmobil\in\orders.dat
Let>endung=.dat
Let>ziel=d:\x400\tmobil\in\orders_%f1%%f2%%f3%_%f4%%f5%%endung%
CopyFile>quelle,ziel
Wait>10
MoveFile>ziel,pfadarchiv
Wait>10
DeleteFile>%quelle%
IfFileExists>d:\EDIalog\daten\appl\empf\orders.dat,In
Goto>End
//Überprüfung ob orders.dat vorhanden ist
Label>Archiv
IfFileExists>d:\x400\tmobil\in\orders.dat,DoArchiv
Goto>In
Label>Start
GetDate>thedate
GetTime>thetime
Day>f1
Month>f2
Year>f3
Hour>f4
Min>f5
IfFileExists>d:\EDIalog\daten\appl\empf\orders.dat,Archiv
Goto>End
//Ausgabe und versendung der E-Mail Nachricht, wenn Timeout in M1 erreicht ist
Label>Error1
GetDate>thedate
GetTime>thetime
CopyFile>c:\txt\error_M1_mail.txt,o:
WriteLn>c:\tmobil.txt,result, %thedate% %thetime% *** Fehler: [TIMEOUT] Makro: M1
Wait>5
DeleteFile>P:\Error_M1.jpg
Goto>ErrorArchiv
//Ausgabe und versendung der E-Mail Nachricht, wenn Timeout in M3 erreicht ist
Label>Error2
GetDate>thedate
GetTime>thetime
CopyFile>c:\txt\error_M3_mail.txt,o:
WriteLn>c:\tmobil.txt,result, %thedate% %thetime% *** Fehler: [TIMEOUT] Makro: M3
Wait>5
DeleteFile>P:\Error_M3.jpg
Goto>ErrorArchiv
//Ausgabe und versendung der E-Mail Nachricht, wenn Timeout in M4 erreicht ist
Label>Error3
CopyFile>c:\txt\error_M4_mail.txt,o:
GetDate>thedate
GetTime>thetime
WriteLn>c:\tmobil.txt,result, %thedate% %thetime% *** Fehler: [TIMEOUT] Makro: M4
Wait>5
DeleteFile>P:\Error_M4.jpg
Goto>ErrorArchiv
//Archivierung beim Auftreten eines Fehlers
Label>ErrorArchiv
Let>quelle=d:\x400\tmobil\in\orders.dat
Let>endung=.dat
Let>ziel=F:\x400\in\ErrorArchiv\orders_%f1%%f2%%f3%_%f4%%f5%%endung%
MoveFile>quelle,ziel
CopyFile>c:\txt\error_archiv_mail.txt,o:
Goto>End
Label>End