How to wait for command window to exit?

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I have loop that calls a Sub that runs the following code:

Dim WinZip As System.Diagnostics.Process
Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName &
".zip @""" & appPth & "WksBkup.txt"""
WinZip.Start("c:\Program Files\WinZip\wzzip.exe", args)
WinZip.WaitForExit()
Do
If WinZip.HasExited = True Then Exit Do
Loop
MsgBox("supposedly exited")

However, it does not wait, and the message box never appears. I get
several command windows running WinZip at simultaneously. The program
does not block, If I click the button again, I get even more
simultaneously running command windows. But I can't get the program to
wait or even show me the messagebox.

Any ideas?
 
Hi,

I prefer to use a processstartinfo for starting an application
with arguments.

http://msdn.microsoft.com/library/d...stemdiagnosticsprocessstartinfoclasstopic.asp

Second Add application.doevents to your loop so it can finish it the
winzip.hasexited is not true when run the first time.

Do
If WinZip.HasExited = True Then Exit Do
Application.DoEvents
Loop

Ken
-------------------
I have loop that calls a Sub that runs the following code:

Dim WinZip As System.Diagnostics.Process
Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName &
".zip @""" & appPth & "WksBkup.txt"""
WinZip.Start("c:\Program Files\WinZip\wzzip.exe", args)
WinZip.WaitForExit()
Do
If WinZip.HasExited = True Then Exit Do
Loop
MsgBox("supposedly exited")

However, it does not wait, and the message box never appears. I get
several command windows running WinZip at simultaneously. The program
does not block, If I click the button again, I get even more
simultaneously running command windows. But I can't get the program to
wait or even show me the messagebox.

Any ideas?
 
Terry Olsen said:
Dim WinZip As System.Diagnostics.Process
Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName &
".zip @""" & appPth & "WksBkup.txt"""
WinZip.Start("c:\Program Files\WinZip\wzzip.exe", args)

=> 'WinZip = Process.Start(...)'.
WinZip.WaitForExit()
Do
If WinZip.HasExited = True Then Exit Do
Loop
MsgBox("supposedly exited")

However, it does not wait, and the message box never appears.

First, try to remove the 'Do...Loop' loop. As you are already using
'WaitForExit' the loop is not necessary.
 
I added the Do...Loop just to see what would happen because the
'WaitForExit' is not waiting...

However, nothing is waiting and I can't figure out why...
 
Terry Olsen said:
I added the Do...Loop just to see what would happen because the
'WaitForExit' is not waiting...

However, nothing is waiting and I can't figure out why...

Are you sure you made the other change I suggested?
 
Back
Top