attaching to COM process in windows service

  • Thread starter Thread starter Trokey
  • Start date Start date
T

Trokey

I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server is started up instead of attaching to the already running one. I have tried the following fixes with no results:

1. added these lines to my service:

System.Threading.Thread.CurrentThread.ApartmentState = ApartmentState.STA;
int ret = CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, 4, 3, IntPtr.Zero, 0, IntPtr.Zero);

2. ran dcomcnfg.exe and changed Default Authentication Level to Default and Default Impersonation Level to Impersonate.

3. Changed the "Log On" settings for the service to use my account/password.

None of these change the situation - however, I still feel it may be a security issue. If I run my app NOT as a service, it works fine.

What's going on here???

Matt
 
its about register your com server as a service. you must replace the clsid\...\localserver32 key with clsid\...\appid = new_guid key. then create the appid\new_guid\localservice key that you've reffered, add (dont miss this step!) appid\your server name.exe key and make it refer to the created appid\new_guid. it may sound a bit complicated, but i've succeeded

in msdn look for 'registering a running exe server' topic. from there (maybe not directly) you can get to the solution. i think you can find some information looking for 'localserver' key in the msdn library.
 
Back
Top