Trouble Getting Word Process in Service Application

P

Phil Galey

I created a service application in VB.NET on Windows 2000 Pro, but right now it's just running on the development workstation.

I'm starting out by checking to see whether Word is already running by using

Dim pcs as Process
Dim psiWord as Process.ProcessStartInfo(<path to WINWORD.EXE>)
Dim wd as Word.Document
Dim wa as Word.Application

For each pcs in Process.GetProcessesByName("WINWORD")
pcs.CloseMainWindow
Next pcs
pcs = Process.Start(psiWord)
Threading.Thread.Sleep(3000)
wd = New Word.Document() <==== ...application is busy. error
wa = wd.Application

But I'm getting the error: "The message filter indicated that the application is busy." when instantiating a new word document. I also notice that if I close the application and then try to kill the Word process through the task manager, it says "Access is denied." Is it possible to automate word from within a service application? Thanks.
 
C

Cindy M.

Hi Phil,

Hmmm. I see numerous messages of people trying to do this,
and no one seems to be able to get it to work. Is there
documentation for this, somewhere?

Personally, coming from the VB-world, I've always used the
equivalent of GetActiveObject. Of course, if Word's not
running, this throws an error - no great problem in the
COM-world, but not so nice in .NET

So I'd try combining your approach with mine: First check
whether the Word process is running. If it is, use
Word.Application wa = GetActiveObject("Word.Application")
Word.Document wd = wa.Documents.Add
I created a service application in VB.NET on Windows
2000 Pro, but right now it's just running on the
development workstation. I'm starting out by checking
to see whether Word is already running by using Dim pcs
as Process Dim psiWord as Process.ProcessStartInfo(<path
to WINWORD.EXE>) Dim wd as Word.Document Dim wa as
Word.Application For each pcs in
Process.GetProcessesByName("WINWORD")
pcs.CloseMainWindow Next pcs pcs =
Process.Start(psiWord) Threading.Thread.Sleep(3000) wd =
New Word.Document() <==== ...application is
busy. error wa = wd.Application But I'm getting the
error: "The message filter indicated that the
application is busy." when instantiating a new word
document. I also notice that if I close the
application and then try to kill the Word process
through the task manager, it says "Access is denied."
Is it possible to automate word from within a service
application?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
J

Jean-Guy Marcil

Phil Galey was telling us:
Phil Galey nous racontait que :
I created a service application in VB.NET on Windows 2000 Pro, but
right now it's just running on the development workstation.

I'm starting out by checking to see whether Word is already running
by using

Dim pcs as Process
Dim psiWord as Process.ProcessStartInfo(<path to WINWORD.EXE>)
Dim wd as Word.Document
Dim wa as Word.Application

For each pcs in Process.GetProcessesByName("WINWORD")
pcs.CloseMainWindow
Next pcs
pcs = Process.Start(psiWord)
Threading.Thread.Sleep(3000)
wd = New Word.Document() <==== ...application is busy. error
wa = wd.Application

But I'm getting the error: "The message filter indicated that the
application is busy." when instantiating a new word document. I
also notice that if I close the application and then try to kill the
Word process through the task manager, it says "Access is denied."
Is it possible to automate word from within a service application?
Thanks.

Just to add to what Cindy as already mentioned, I noticed something
inherently wrong in your code:
wd = New Word.Document()
wa = wd.Application

You cannot define a document (wd) and then use that object to define the
Word application itself (wa). The Word Document is a "child" of the Word
Application, so you have to do it the other way around:
wa = New Word.Application
wd = wa.Documents.Add

Unless I totally misunderstood what you are trying to do, of course...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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