简体   繁体   中英

Invoke a method from another process

I have an application I got from work. Now I'm trying to program the ability to automatically click a button. For this to work, I need to get inside.

I can easily see the source code with a decompiler, so I know all the class names, method names, etc...

I've been looking into Types and the Type.GetMethod() Method. Only problem is that I try to work with the process of the app. I capture the right app (Process.GetProcessByName("WorkProcess")), I can capture the 'Type', but I don't know how to get to the right class, and invoke the right method.

I'll give you a layout that's shown in the decompiler:

WorkApp
> WorkApp.Exe
--> References
--> <Default namespace>
--> WORKAPP
----> frmsomething (Form)
------> _btnsync : Button
------> btnsync : Button

Any ideas on how to do this? I searched google, but couldn't find an answer...

Thank you Anthony

PS: I don't have access to the source code of the app from work.

PPS: This is the code I have thusfar:

    Process WA = null;

    private void Initialize()
    {
        Process[] pa = Process.GetProcesses();

        foreach (Process p in pa)
        {
            if (p.ProcessName.Contains("WorkApp"))
            {
                WA = p;
                break;
            }
        }

        if (WA == null)
        {
            Console.WriteLine("App was not found...");
            stop = true;
        }
        else
        {
            Type t = WA.GetType();
            t.GetType();
            // This is the place I got stuck
        }
    }

if you are trying to invoke a method in an application from outside world of it, one way is to Create Remote thread in that application, and using that dll from inside that application, do the work using Reflection. I did this to an application and it worked. if you want details, comment on my answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM