Jump to content

Identify .NET controls by their Name


zfisherdrums
 Share

Recommended Posts

Have you had any of the following problems when trying to identify controls in a .NET app:

- the control ClassNameNN changes often

- cannot obtain any information that uniquely identifies the control

Often times, we are stuck trying to identify them using less than robust means. Fortunately, there is the WM_GETCONTROLNAME message. Using this, one can identify a .NET control by the name given by the developer at design time ( or given at run-time ).

Attached is a port to AutoIT from a C++ example posted here.

NET_DumpAllControlNames will dump all control names for a given .NET Windows Form.

NET_ControlGetHandleByName will provide a handle for a given control name on a Windows Form

Example:

#include <DotNetIdentification.au3>

; "Test App" is a fictitous application that contains a control named "txtShowMe". 
$WindowName = "Test App"
$WindowText = ""

$control = NET_ControlGetHandleByName( $WindowName, $WindowText, "txtShowMe" )
if @error = 0 then 
    WinActivate( $WindowName, $WindowText )
    ControlFocus( $WindowName, $WindowText, $control )
endif

NOTE:

- Not all .NET controls have unique names assigned to them.

- Also, this will NOT provide access to cells in a .NET Data Grid. For those, take a look at MS Active Accessibility implemented in oleacc.dll and its AutoIT implementation here.

- If you wish to discover the names of specific controls using a utility similar to the AutoItInfo tool, check out Managed Spy or Ranorex Spy.

TODO:

- Break out Setup and Cleanup into distinct functions

- Fill out error handling

- Once registering OnAutoITExit functions is implemented, cleanup on errors

DotNetIdentification.au3

Edited by zfisherdrums
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
  • 1 month later...
  • 5 months later...
  • 4 months later...

putting in a long delayed thanks. best and most useful code i have seen on the site. unfortunately pretty much everything flies over my head.

Thanks for sharing.

Indeed... this is very nice. So much Windows software is written in .NET now that it would be nice if AutoIt had more extensive support for Windows Forms, etc.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

Hi all

Why NET_DumpAllControlNames could not get names of some controls on .NET froms?

This names could be got by other programs for automate testing but in this case $control = NET_ControlGetHandleByName( $WindowName, $WindowText, "<Control Name>" ) does not work.

Have you had any of the following problems when trying to identify controls in a .NET app:

- the control ClassNameNN changes often

- cannot obtain any information that uniquely identifies the control

Often times, we are stuck trying to identify them using less than robust means. Fortunately, there is the WM_GETCONTROLNAME message. Using this, one can identify a .NET control by the name given by the developer at design time ( or given at run-time ).

Attached is a port to AutoIT from a C++ example posted here.

NET_DumpAllControlNames will dump all control names for a given .NET Windows Form.

NET_ControlGetHandleByName will provide a handle for a given control name on a Windows Form

Link to comment
Share on other sites

  • 3 months later...

Hello all,

I've noticed that the script does not return all the objects having the same name if a lot of them are present in the user application. For example, the script works great on my application if I have 66 object sharing the same name. If I add more than that, the others are not seen anymore. I've change to buffer size to a bigger value but it has not worked. Does anyone know where this limitation is coming from?

Thank you,

Ionut

Link to comment
Share on other sites

  • 1 month later...

Have you had any of the following problems when trying to identify controls in a .NET app:

- the control ClassNameNN changes often

- cannot obtain any information that uniquely identifies the control

Often times, we are stuck trying to identify them using less than robust means. Fortunately, there is the WM_GETCONTROLNAME message. Using this, one can identify a .NET control by the name given by the developer at design time ( or given at run-time ).

Attached is a port to AutoIT from a C++ example posted here.

NET_DumpAllControlNames will dump all control names for a given .NET Windows Form.

NET_ControlGetHandleByName will provide a handle for a given control name on a Windows Form

Example:

#include <DotNetIdentification.au3>

; "Test App" is a fictitous application that contains a control named "txtShowMe". 
$WindowName = "Test App"
$WindowText = ""

$control = NET_ControlGetHandleByName( $WindowName, $WindowText, "txtShowMe" )
if @error = 0 then 
    WinActivate( $WindowName, $WindowText )
    ControlFocus( $WindowName, $WindowText, $control )
endif

NOTE:

- Not all .NET controls have unique names assigned to them.

- Also, this will NOT provide access to cells in a .NET Data Grid. For those, take a look at MS Active Accessibility implemented in oleacc.dll and its AutoIT implementation here.

- If you wish to discover the names of specific controls using a utility similar to the AutoItInfo tool, check out Managed Spy or Ranorex Spy.

TODO:

- Break out Setup and Cleanup into distinct functions

- Fill out error handling

- Once registering OnAutoITExit functions is implemented, cleanup on errors

above link for "DotNetIdentification.au3" is throwing an error that

these constant cannot be renamed

Const $PROCESS_VM_OPERATION = 0x8

Const $PROCESS_VM_READ = 0x10

Const $PROCESS_VM_WRITE = 0x20

Const $PROCESS_ALL_ACCESS = 0xFFFF

and commenting these constant "NET_ControlGetHandleByName( $WindowName, $WindowText, "txtuser" )"

does not return the handle of the window.

Link to comment
Share on other sites

  • 1 month later...

above link for "DotNetIdentification.au3" is throwing an error that

these constant cannot be renamed

Const $PROCESS_VM_OPERATION = 0x8

Const $PROCESS_VM_READ = 0x10

Const $PROCESS_VM_WRITE = 0x20

Const $PROCESS_ALL_ACCESS = 0xFFFF

Anyone figured out what's causing this issue?

Edited by TwistedGA
Link to comment
Share on other sites

  • 5 months later...
  • 3 weeks later...

I am worried because I cannot get the Class Instance or Control ID by using "AU3Info" tool in WPF application of the .NET.

It does not go well though there are variously writings in Forums.

I am afraid of the lack of learning the software, but please tell me the usage of Example program for details.

I could not get Class Instance or Control ID when the program was executed.

No executing errors occurs.

Link to comment
Share on other sites

  • 3 months later...
  • 10 months later...

I commented out the 4 offending consts as well, and it works for me, at least the NET_DumpAllControlNames() function works. So that's fine. However what I'm trying to accomplish looks more involved so I may give up and try some other way of automating this WPF app.

Just remember it is possible that some people's WPF app is actually sitting inside another winforms window, which makes things a little harder. I think I have such situation.

Link to comment
Share on other sites

  • 7 months later...

I have a question regarding this .net handles return.

If we can find the handles would it possible to retrieve the info/text from the handles?

Autoit natively unable to retrieve anything from .net handle since it always return 0 for me.

Any suggestion?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...