Board index » cppbuilder » COM object server as a service

COM object server as a service

I'm trying to develop a service application wich hosts one or more COM
objects.  To achieve this, I create a new Service Application and then
add one Automation Object.  I install the service and it gets registered
in the SCM's database. The service can then be succesfully
started/stopped and so on via the Service Control Panel.  The COM class
gets registered as well.  The problem lies here: when I try to
instantiate my COM server a second copy of the server program loads into
memory as a second process.  This second instance of the server is the
one who actually my client is connected to.  I can call methods on this
instance, but it gets unloaded from memory a few seconds later.

How can I connect to the process running the service?  I've read
somewhere that this problem migth be related to security/impersonation
issues.  Tried to follow some registry changes but nothing worked. Any
ideas on the subject?  The service is running under the local system
account.

Thank You

Ernesto DelVillar

 

Re:COM object server as a service


Hello Ernesto,
I suspect your 2nd copy is being run directly via normal automation. I have
a Win9x service that does the same thing.
What I did was to check in WinMain() to see if the word "AUTOMATION" appears
on the command line (ie. in ParamStr(1)), and then do a return 0 to prevent
the 2nd copy from running. Just make sure you call Application->Initialize()
first.
HTH
Richard Kable
Source Communications
Melbourne, Australia

Ernesto del Villar <edelvil...@usa.net> wrote in message
news:380DF8D4.5C58AA7A@usa.net...

Quote

> I'm trying to develop a service application wich hosts one or more COM
> objects.  To achieve this, I create a new Service Application and then
> add one Automation Object.  I install the service and it gets registered
> in the SCM's database. The service can then be succesfully
> started/stopped and so on via the Service Control Panel.  The COM class
> gets registered as well.  The problem lies here: when I try to
> instantiate my COM server a second copy of the server program loads into
> memory as a second process.  This second instance of the server is the
> one who actually my client is connected to.  I can call methods on this
> instance, but it gets unloaded from memory a few seconds later.

> How can I connect to the process running the service?  I've read
> somewhere that this problem migth be related to security/impersonation
> issues.  Tried to follow some registry changes but nothing worked. Any
> ideas on the subject?  The service is running under the local system
> account.

> Thank You

> Ernesto DelVillar

Re:COM object server as a service


Thank you Richard.

You're right, the second instance is running just like any automation server.  I
made the WinMain stuff but the problem is still happening.  I can't get
connected to the service process to create my COM objects.  The service was
originally running under the LocalService account.  I changed the settings in
the service control panel an made it run under my domain account, but the
problem is still here.  When the latter change is made one strange thing happen:
I ran PULIST to see the processes in memory, and the service process appears as
having no associated account.  I still believe it's just a matter of setting
appropiate permissions and/or RunAs parameters in the registry.  Any ideas?

BTW, i'm running NT4 SP4

Thak you all,

Ernesto

Quote
Richard Kable wrote:
> Hello Ernesto,
> I suspect your 2nd copy is being run directly via normal automation. I have
> a Win9x service that does the same thing.
> What I did was to check in WinMain() to see if the word "AUTOMATION" appears
> on the command line (ie. in ParamStr(1)), and then do a return 0 to prevent
> the 2nd copy from running. Just make sure you call Application->Initialize()
> first.
> HTH
> Richard Kable
> Source Communications
> Melbourne, Australia

> Ernesto del Villar <edelvil...@usa.net> wrote in message
> news:380DF8D4.5C58AA7A@usa.net...

> > I'm trying to develop a service application wich hosts one or more COM
> > objects.  To achieve this, I create a new Service Application and then
> > add one Automation Object.  I install the service and it gets registered
> > in the SCM's database. The service can then be succesfully
> > started/stopped and so on via the Service Control Panel.  The COM class
> > gets registered as well.  The problem lies here: when I try to
> > instantiate my COM server a second copy of the server program loads into
> > memory as a second process.  This second instance of the server is the
> > one who actually my client is connected to.  I can call methods on this
> > instance, but it gets unloaded from memory a few seconds later.

> > How can I connect to the process running the service?  I've read
> > somewhere that this problem migth be related to security/impersonation
> > issues.  Tried to follow some registry changes but nothing worked. Any
> > ideas on the subject?  The service is running under the local system
> > account.

> > Thank You

> > Ernesto DelVillar

Re:COM object server as a service


The solution was incredibly simple:

In order to make a COM server application to run as a service under NT just follow
these steps.

1. Create a Service Application project using the appropiate wizard in BCB.
2. Create one or more COM (or automation) objects in that project and define and
implement methods of declared interfaces.
3. Install the application in the Service Mgr Database by running it with /INSTALL
as the only parameter.
4. Register the COM classes and the server application in the registry by running
the program, but now with no parameters.
5. Under HKEY_CLASSES_ROOT\AppID\{clsid}\ define a new string value named
LocalService.  Assign it a value equal to the service name, for example MyService.
Note that the service name is exactly the same that appears under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
6. LocalService value instruct COM to rely on the running service for creating new
objects.  BTW if the service is not running (and if it is enabled) creating one of
the COM classes defined in that server automatically starts the service.
7.  There's no need to set up special permissions or to run the service under a
special user account.

Hope this to be useful ...

See you folks.

Quote
Ernesto del Villar wrote:
> Thank you Richard.

> You're right, the second instance is running just like any automation server.  I
> made the WinMain stuff but the problem is still happening.  I can't get
> connected to the service process to create my COM objects.  The service was
> originally running under the LocalService account.  I changed the settings in
> the service control panel an made it run under my domain account, but the
> problem is still here.  When the latter change is made one strange thing happen:
> I ran PULIST to see the processes in memory, and the service process appears as
> having no associated account.  I still believe it's just a matter of setting
> appropiate permissions and/or RunAs parameters in the registry.  Any ideas?

> BTW, i'm running NT4 SP4

> Thak you all,

> Ernesto

> Richard Kable wrote:

> > Hello Ernesto,
> > I suspect your 2nd copy is being run directly via normal automation. I have
> > a Win9x service that does the same thing.
> > What I did was to check in WinMain() to see if the word "AUTOMATION" appears
> > on the command line (ie. in ParamStr(1)), and then do a return 0 to prevent
> > the 2nd copy from running. Just make sure you call Application->Initialize()
> > first.
> > HTH
> > Richard Kable
> > Source Communications
> > Melbourne, Australia

> > Ernesto del Villar <edelvil...@usa.net> wrote in message
> > news:380DF8D4.5C58AA7A@usa.net...

> > > I'm trying to develop a service application wich hosts one or more COM
> > > objects.  To achieve this, I create a new Service Application and then
> > > add one Automation Object.  I install the service and it gets registered
> > > in the SCM's database. The service can then be succesfully
> > > started/stopped and so on via the Service Control Panel.  The COM class
> > > gets registered as well.  The problem lies here: when I try to
> > > instantiate my COM server a second copy of the server program loads into
> > > memory as a second process.  This second instance of the server is the
> > > one who actually my client is connected to.  I can call methods on this
> > > instance, but it gets unloaded from memory a few seconds later.

> > > How can I connect to the process running the service?  I've read
> > > somewhere that this problem migth be related to security/impersonation
> > > issues.  Tried to follow some registry changes but nothing worked. Any
> > > ideas on the subject?  The service is running under the local system
> > > account.

> > > Thank You

> > > Ernesto DelVillar

Other Threads