How to wait for command window to exit?

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?
 
K

Ken Tucker [MVP]

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?
 
H

Herfried K. Wagner [MVP]

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.
 
T

Terry Olsen

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...
 
H

Herfried K. Wagner [MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top