简体   繁体   中英

How can I access objects in other applications with C#?

I want to access the objects and their properties in a similar way to how automation tools access them in their "UI Map" functionality. I'm assuming there's an assembly reference that will give access to running processes and whatever objects exist for that process.

Specifically, I need to access a few label control text properties in another running application.

Also, sorry if this is a duplicate - I looked around, but I'm not sure what keywords would get me to what I need.

This is not a common practice in C#. The term that you are looking for is to "spy" another window/application/process. There are several resources here in StackOverflow talking about this. For example:

How can I get functionality similar to Spy++ in my C# app?

To access a control in another Win32 form you need to look for the handle of that element.

For WPF applications, the UI Automation libraries present in .NET 4.5 make this way simpler: http://msdn.microsoft.com/en-us/library/ms747327.aspx

For older winforms applications, you'll have to actually utilize pInvoke on the User32 API. The example link Pete gave you in the comment on your question will help guide you in that direction: http://www.pinvoke.net/default.aspx/user32.enumwindows

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