Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Identify .NET controls by their Name


  • Please log in to reply
28 replies to this topic

#1 zfisherdrums

zfisherdrums

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 391 posts

Posted 31 August 2008 - 06:51 AM

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

Attached Files


Edited by zfisherdrums, 24 October 2008 - 07:31 PM.

  • allenljwan likes this







#2 taralex

taralex

    Seeker

  • Active Members
  • 9 posts

Posted 04 November 2008 - 10:37 PM

great tool, thank you!

#3 dmob

dmob

    Polymath

  • Active Members
  • PipPipPipPip
  • 235 posts

Posted 08 December 2008 - 04:43 PM

oh yes! Thank you! Thank you!

I've been wrestling with such controls for a while. This will make it SO MUCH easier.

Thank you

#4 yqf0215

yqf0215

    Seeker

  • Active Members
  • 16 posts

Posted 09 December 2008 - 09:59 AM

Do a good job, If we can control the .net controls as native controls, much better.

#5 susall

susall

    Seeker

  • Active Members
  • 24 posts

Posted 15 December 2008 - 12:30 PM

Can you tell me where to find "SendMessage.au3" ? I checked the AutoIT program files folder and I don't see it in there.

-su

#6 susall

susall

    Seeker

  • Active Members
  • 24 posts

Posted 15 December 2008 - 01:55 PM

Can you tell me where to find "SendMessage.au3" ? I checked the AutoIT program files folder and I don't see it in there.

-su


Sorry... I had to update my version of autoit.... now I have that part worked out.

#7 zip1300

zip1300

    Seeker

  • New Members
  • 1 posts

Posted 29 January 2009 - 02:27 PM

Fantastic. This will make life so much easier.

Well done. :)

#8 Rishav

Rishav

    Polymath

  • Active Members
  • PipPipPipPip
  • 201 posts

Posted 02 July 2009 - 09:35 AM

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.

#9 clevername47

clevername47

    Seeker

  • Active Members
  • 27 posts

Posted 12 November 2009 - 06:17 PM

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.

#10 Matej

Matej

    Seeker

  • Normal Members
  • 5 posts

Posted 25 November 2009 - 02:06 PM

What about windows? Window classnames are also very variable so is there any way to identify window by form name?

#11 Alchemist

Alchemist

    Seeker

  • Active Members
  • 7 posts

Posted 17 March 2010 - 05:23 PM

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



#12 ionut

ionut

    Seeker

  • Active Members
  • 44 posts

Posted 14 July 2010 - 01:48 PM

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

#13 tonauac

tonauac

    Seeker

  • New Members
  • 2 posts

Posted 28 August 2010 - 07:11 AM

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.

#14 TwistedGA

TwistedGA

    Seeker

  • Active Members
  • 18 posts

Posted 04 October 2010 - 01:47 PM

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, 04 October 2010 - 01:48 PM.


#15 shen

shen

    Seeker

  • New Members
  • 1 posts

Posted 17 March 2011 - 05:48 AM

Anyone figured out what's causing this issue?

Those const already defined in ProcessConstants.au3 which included in Memory.au3. you can comments them and the script still work fine.

#16 BelieverofAutoIt

BelieverofAutoIt

    Seeker

  • Active Members
  • 9 posts

Posted 04 April 2011 - 10:28 AM

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.

#17 EnzoM

EnzoM

    Seeker

  • New Members
  • 4 posts

Posted 29 July 2011 - 09:08 PM

I commented out the four offending "const" lines and it runs without error, but the script returns 0 for $control. Ideas? I need to get control of a .NET 3.5 application that uses WPF.

#18 zaphodikus

zaphodikus

    Seeker

  • Normal Members
  • 6 posts

Posted 25 June 2012 - 03:10 PM

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.

#19 Mun

Mun

    Seeker

  • Active Members
  • 47 posts

Posted 10 February 2013 - 02:17 AM

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?

#20 junkew

junkew

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 592 posts

Posted 10 February 2013 - 12:57 PM

With ui automation you can also retrieve information about .NET controls
http://www.autoitscript.com/forum/topic/128406-interface-autoitobject-iuiautomation
http://www.autoitscript.com/forum/topic/147014-objcreateinterface-and-struct-tagpoint-in-method-elementfrompoint




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users