By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,662 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,662 IT Pros & Developers. It's quick & easy.

How to wait for command window to exit?

P: n/a
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?

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Hi,

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

http://msdn.microsoft.com/library/de...classtopic.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
-------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
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?

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #2

P: n/a
"Terry Olsen" <to******@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
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...
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uJ*************@TK2MSFTNGP15.phx.gbl...
"Terry Olsen" <to******@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
"Terry Olsen" <to******@hotmail.com> schrieb:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.