473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Waiting for com program to terminate

Bob
I launch Word from within my application (Vs2005, VB) and I would like to
make it necessary for the just opened Word to be closed before the rest of
my code in the calling sub can execute. How can I do this?

Thanks for any help
Bob
Aug 14 '06 #1
2 1756
Hello, Bob,

This isn't "elegant", but seems to work:

Imports System.Threading.Thread
Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form
. . .
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim appWord As New Word.Application
appWord.Visible = True
MsgBox("Waiting for Word to close...")

Do
Try
' Examine some (any) property of Word application.
Dim booTest As Boolean = appWord.Visible
Sleep(100)

Catch ex As COMException
If (ex.ErrorCode = &H80010108) Then
' object has disconnected from its clients.
MsgBox("Continuing...")
Exit Do
Else
' Unexpected error.
Throw New Exception(ex.Message, ex)
End If

Catch ex As Exception
' Unexpected error.
Throw New Exception(ex.Message, ex)

End Try
Loop

End Sub

End Class

Cheers,
Randy
Bob wrote:
I launch Word from within my application (Vs2005, VB) and I would like to
make it necessary for the just opened Word to be closed before the rest of
my code in the calling sub can execute. How can I do this?

Thanks for any help
Bob

Aug 15 '06 #2
Hello again, Bob,

I've just seen your later post, and (if your staring Word as a process
rather than as an application) Cor's answer there is much better . That is:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

Dim procWord As Process = Process.Start("Mydoc.doc")

MsgBox("Waiting for Word to close...")
procWord.WaitForExit()
MsgBox("Continuing...")

End Sub

Cheers,
Randy
R. MacDonald wrote:
Hello, Bob,

This isn't "elegant", but seems to work:

Imports System.Threading.Thread
Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form
. . .
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim appWord As New Word.Application
appWord.Visible = True
MsgBox("Waiting for Word to close...")

Do
Try
' Examine some (any) property of Word application.
Dim booTest As Boolean = appWord.Visible
Sleep(100)

Catch ex As COMException
If (ex.ErrorCode = &H80010108) Then
' object has disconnected from its clients.
MsgBox("Continuing...")
Exit Do
Else
' Unexpected error.
Throw New Exception(ex.Message, ex)
End If

Catch ex As Exception
' Unexpected error.
Throw New Exception(ex.Message, ex)

End Try
Loop

End Sub

End Class

Cheers,
Randy
Bob wrote:
>I launch Word from within my application (Vs2005, VB) and I would like
to make it necessary for the just opened Word to be closed before the
rest of my code in the calling sub can execute. How can I do this?

Thanks for any help
Bob
Aug 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joseph Suprenant | last post by:
Hello all, I have a C++ program, it does some calculations on things and then prints out a file in the format in which GNUPLOT can use. So my question is how would i call GNUPLOT from my C++...
3
by: Ted | last post by:
In doing a db2 list applications show detail, I have 320 entries applications. Of those sometimes all of them are "UOW Waiting." Ususally there are from 1 to 4 marked UOW Executing. The rest...
20
by: Charles Law | last post by:
Consider the following scenario: A data packet is sent out of a serial port and a return packet is expected a short time later. The application sending the packet needs to send another packet...
3
by: Mr Dyl | last post by:
I'm using Boost to run a couple of threads, one of which reads commands via std::cin and another receives them through a socket. It's entirely possible that during the life of the app, all...
6
by: Hugh Janus | last post by:
Hi group, I am executing a shell command that calls a .BAT file. I have to wait for this batch file to finish so I use the wait = true parameter in the shell command. However, this means that...
5
by: Daz | last post by:
Hi everyone, Sorry about the long thread name, I think that my problem is that I don't know how to word it, which is why I have been unsuccessful finding the information I require. I am...
3
by: norm4h8 | last post by:
Hi! I have a question about how to create a process in such a way that it would terminate itself if its wated for input for too long. Here is the story. I have 2 different files, say R.c and...
4
by: cnoobie | last post by:
Problem 1 - Min, Mean, Max Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.