1

I am trying to connect to an application that exposes a COM interface. My VbScript Code looks like this:

  Set App = CreateObject( "Starter.Application")
  Set Measurement = App.Measurement
  WScript.ConnectObject App, "App_"

  If Measurement.Running Then
      Measurement.Stop
  End If

This allows me to Control variables within the Starter-Application.

What I want to do now is connect another application to the same COM interface, to influence other variables within the application. Naturally, when I start the application using the CreateObject command, I get a new instance of the application.

How can I connect to the same instance that was already created with another script?

Blackwood
  • 4,504
  • 16
  • 32
  • 41
tarrasch
  • 2,630
  • 8
  • 37
  • 61
  • You'll have to use GetObject() to connect to an existing instance. Whether that's possible and what you need to pass as an argument requires using a telephone. – Hans Passant Aug 31 '15 at 17:35

1 Answers1

0

Q: How can i connect to the same instance that was already created with another script?

A: Make your COM server an "out of process" .exe:

https://msdn.microsoft.com/en-us/library/Aa242100%28v=VS.60%29.aspx

https://msdn.microsoft.com/en-us/library/windows/desktop/ms683835%28v=vs.85%29.aspx

NOTE:

If your COM/ActiveX application is already out of process - but doesn't "share" state like you need, you can create your own VB6 out of process exe to "wrap" the original application.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Does not seem to work for me. Replicated this with python now. – tarrasch Sep 01 '15 at 06:41
  • It's absolutely possible for multiple COM/ActiveX clients to share state. One common way to do this is with an "Out of Process COM Server", implemented as a "singleton". Perhaps you can modify your application to be an "Out of process singleton". Otherwise, you can write your own (e.g. VB6 or C++/ATL) application that *IS* a singleton, and does nothing more than "wrap" a single, shared instance of your application for your VBS (or Python!) client scripts: http://stackoverflow.com/questions/11817822/out-of-process-com-singletons. – paulsm4 Sep 03 '15 at 18:24
  • Did you call CoRegisterClassObject in your COM server with flags=REGCLS_MULTIPLEUSE? – Bart Sep 06 '15 at 11:19