GetObject function in windows services

  • Thread starter Thread starter Andrei
  • Start date Start date
A

Andrei

Hello,

I posted yesterday the same problem, but now I want to be
more specific about it.

My intention is to create a windows service to process
some Word documents. If I use CreateObject to create a
reference to a Word object everything is working fine.

If I use GetObject to get a reference to Word object (of
course that Word applicaton is started) I get an error
("Cannot create ActiveX component")

It is like my service cannot detect that Word application
is started.

I want to say that GetObject is working fine from a
standard Windows application.

Thank you,
Andrei
 
Hello,

I posted yesterday the same problem, but now I want to be
more specific about it.

My intention is to create a windows service to process
some Word documents. If I use CreateObject to create a
reference to a Word object everything is working fine.

If I use GetObject to get a reference to Word object (of
course that Word applicaton is started) I get an error
("Cannot create ActiveX component")

It is like my service cannot detect that Word application
is started.

I want to say that GetObject is working fine from a
standard Windows application.

Thank you,
Andrei

I'm unclear as to what is working and what is not for you? Are you
saying GetObject() works for getting the reference to the application,
but not other classes inside the application? Getobject() is only for
getting a reference to the application. You don't use it to get a
Document class instance. instead use the Documents property of the
Application instance!

Here is the code I use to get a reference to an application object in
AutoCAD. This should be very similar for a Word application:

mcadApplication = (AutoCAD.AcadApplicationClass)
Marshal.GetActiveObject("AutoCAD.Application");

It works similarly to GetObject.
 
Hi Michael,

Thank you for your reply. I will try to be more clear.

GetObject is returning me an error when I try to get a
reference to the Word application. But this is happening
only in windows services, in a standard windows
application I have no error.

CreateObject is working fine in both cases (windows
services or windows applications)

My question is why I cannot use GetObject in a windows
sevice?

Thank you,
Andrei
 
Hi Michael,

I have tried using Marshal.GetActiveObject instead of
GetObject as you suggested. I got an error : "Operation
unavailable"

Andrei,
 
Hi Michael,

I have tried using Marshal.GetActiveObject instead of
GetObject as you suggested. I got an error : "Operation
unavailable"

Andrei,

Sorry, I've never made a Windows Service. I don't know why it would work
on Windows Forms and not a Windows Service?
 
This is the kind of thing that smells of a security issue. Your Service is
probably running with the LocalSystem account in its own Windowstation, but
trying to drive a Word application that may be installed for a different
user, or that can't access the interactive user's desktop.

What happens if you run the Service under your account name/password?
 
Back
Top