0

Been trawling code segments here and I can't seem to get my head around this. I think I might be searching for the wrong keywords or maybe i'm asking something inherently stupid. Let's see.

I am using a 3rd party automation software built on VB that can interact with applications (rather well usually and in this case a mainframe application) however I have come across an application recently that when it launches the application it also binds to the application (which is normal I know) and can terminate the application to detach from it also.

My problem now arises when I want to write a second class of code to interact with this application. If we imagine my first class contains simple basic methods like launch/terminate/sendkey and read from screen objects, the second class I would like it to contain methods I can sue for the next set of screens I come across in the application. My problem here is the GUI of this 3rd party automation software is not giving me the option to 'Attach' to the running instance of an application. So now I find myself trying to code in a way to detect running processes and attaching to the running instance of the mainframe application I'm looking to automate on.

So far I've tried various code but I have landed on this to find me the running process I'm looking for

Dim ps As System.Diagnostics.Process
For Each ps In System.Diagnostics.Process.GetProcessesByName(System.Net.Dns.GetHostName)
    If ps.Equals("PROCESS NAME")
        'bind to the process
        ps.Bind
    End If
Next ps

Basically this says, create an empty process object, then loop over every process you can find running on the local machine. If you find one with this certain name then do something otherwise continue. Eventually ill write process not found code in the outer part but what I'm trying to do is get this running piece of code to attach or bind itself to the running mainframe process. What is the code to do this? What is the library to do his if someone can point me that way I'll fiddle till I get it right and put it back here.

So far I've looked here in MSDN Process class listing System.diagnostic.process

Went through all the methods but nothing strikes me as a binding or attaching mechanism.

and i have looked at a few other question around here on SO as well but none pertain to what Im looking for exactly

Attach second exe to main process

not stack-O but still not what I wanted exactly, runtime binding article

MSDN 'how to bind to existing process'

This link says how to bind but all it says is how to list processes and then close one by an index which isn't what im looking for.

I've googled 'how to attach to running application vb' and many variants of it including bind/ visual basic/ existing etc etc but no results and importantly i'm NOT looking for how to attach visual studio to a process. I'm not using visual studio I don't need to know how to attach that to a process (these search terms return this as top result had to use -studio -debugger to get better results back)

I think I have a fundamental misunderstanding of how VB processes attach to applications so maybe i'm programming this all wrong, but any feedback or guides ot thoughts welcome.

Cheers -DW

Community
  • 1
  • 1
Dexter Whelan
  • 414
  • 3
  • 15

0 Answers0