Results 1 to 10 of 10

Thread: Attach to running instance of application via process

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Attach to running instance of application via process

    I am working on an app to interface with a CAD program. What I would like to do is not only create a new application object, but add ability attach to a current running instance. I can create the object like this:

    Code:
     Dim rhinoApp As Rhino5x64Application
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Try
                rhinoApp = New Rhino5x64Application()
                rhinoApp.Visible = True
            Catch ex As Exception
                MessageBox.Show("Could not create Rhino Application!", "Error Creating Object!", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
    
        End Sub
    I can detect the current running instances of the application like so:

    Code:
            For Each p In Process.GetProcessesByName("Rhino4")
                ListBox1.Items.Add(p.ProcessName & " - " & p.MainWindowTitle)
            Next p
    Question is, how do I assign the process to an object so i can ctype it to an instance of my application? Pseudo-code sort of like

    Code:
            Try
                Dim prc As process = myprocess
                Dim rhinoScriptingObject = CType(prc, Rhino5x64Application)
             Catch ex As Exception
                MessageBox.Show("Could not create scripting object! Make sure that Rhino is instantiated already", "Error Instantiating Scripting!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End Try
    Last edited by jayinthe813; Oct 7th, 2013 at 06:31 PM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: Attach to running instance of application via process

    Hi,

    i know you can manipulate another program using API, and grab references to it with code but to access it and manipulate it directly i think is going to be a tough job, unless it has be designed with this in mind you will basically have to hack it open.

    maybe one of the other guys has more insight.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Attach to running instance of application via process

    Quote Originally Posted by GBeats View Post
    Hi,

    i know you can manipulate another program using API, and grab references to it with code but to access it and manipulate it directly i think is going to be a tough job, unless it has be designed with this in mind you will basically have to hack it open.

    maybe one of the other guys has more insight.
    I have seen getactiveobject but I do no think that's what I really looking to do. I would think somehow you could ctype() from existing application object (maybe through windows shell?) to the correct object interface. I can do this with internet explorer fairly easily, but I am having trouble with this...

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Attach to running instance of application via process

    You obviously have an import for this Rhino5x64Application type object. This class would presumably be a wrapper around starting the process and holding onto the stdin/stdout amongst possibly other things. If you wanted to try to connect to an existing process (started directly by the user?) then this wrapper would not exist, so you would have no method to get hold of it.

    You would have to find out how this Rhino5x64Application library starts the process, how and what it does to connect to it, and then somehow workout if connecting to the app in the same way is even possible while it is already running..... Good luck

  5. #5
    New Member
    Join Date
    Jan 2015
    Posts
    1

    Re: Attach to running instance of application via process

    jayinthe813, did you succeed to RunScript on an already open instance of Rhino? Once you get the process id how can you do?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Attach to running instance of application via process

    Quote Originally Posted by Lore View Post
    jayinthe813, did you succeed to RunScript on an already open instance of Rhino? Once you get the process id how can you do?
    No, I was unable to attach to an existing instance of Rhino, so I just created a new instance a runtime instead. For my needs attaching to an existing rhino instance was a nice to have but not necessary. I tried a bunch of stuff but couldn't get it to work. You could try asking on the McNeel forum:

    http://discourse.mcneel.com/

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,397

    Re: Attach to running instance of application via process

    What is Rhino5x64Application(), why would you loop processes to detect instances when the functionality is already provided for you. Is there a reason you are not using My.Application.StartupNextInstance Event?

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,474

    Re: Attach to running instance of application via process

    IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,397

    Re: Attach to running instance of application via process

    Quote Originally Posted by techgnome View Post
    IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.

    -tg
    That explains it if true. Thanks TG

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Attach to running instance of application via process

    Quote Originally Posted by ident View Post
    What is Rhino5x64Application(), why would you loop processes to detect instances when the functionality is already provided for you. Is there a reason you are not using My.Application.StartupNextInstance Event?
    Rhino is a 3D modeling application. Rhino5x64Application() is the class in the DLL that you use to create a new instance of the application. It is found in a DLL that is referenced from the COM tab. It is similar to something like Excel Interop. It lets you control Rhino from outside of the actual application to perform automation.

    The purpose of doing this would be to let someone work in the application, then launch a .NET app, attach to the instance using process name and run some automation or something. I found its just as easy to create the instance from .NET application, work in it, then run the automation from the app.

    Quote Originally Posted by techgnome View Post
    IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.

    -tg
    I have no idea still what is the appropriate way, but this was an old project and I don't feel like posting over on the dev forums.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width