Jon

Using AutoItX from C# / .Net

11 posts in this topic

The following files are provided to allow .NET use:

  • AutoItX3.Assembly.dll - The .NET Assembly for using AutoItX.
  • AutoItX3.Assembly.xml - The Visual Studio Intellisense help file for the .NET Assembly.
  • AutoItX3.dll - The main AutoItX DLL (x86)
  • AutoItX3_x64.dll - The main AutoItX DLL (x64)

Using the Assembly from VB/C# within in Visual Studio is very easy:

  • Add a reference to AutoItX3.Assembly.dll to your project
  • Add a using AutoIt; statement in the files you want to use AutoIt functions
  • Write code like this C# example:
using AutoIt;

...

// Wow, this is C#!
AutoItX.Run("notepad.exe");
AutoItX.WinWaitActive("Untitled");
AutoItX.Send("I'm in notepad");
IntPtr winHandle = AutoItX.WinGetHandle("Untitled");
AutoItX.WinKill(winHandle);
  • Distribute your final executable with the files AutoItX3.Assembly.dll, AutoItX3.dll, AutoItX3_x64.dll.
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

nice and easy but got error when run, Autoitx3.Dll can not access.

 reg dll like this "regsvr32 c:\AutoitX\AutoitX3.dll" for use, got an error 

what can i do now for using autoitx in C#

i'm using VS community 2015.

autoit error run.jpg

autoit error reg.jpg

Edited by xhuyvn

Share this post


Link to post
Share on other sites

nice and easy but got error when run, Autoitx3.Dll can not access.

 reg dll like this "regsvr32 c:\AutoitX\AutoitX3.dll" for use, got an error 

what can i do now for using autoitx in C#

i'm using VS community 2015.

autoit error run.jpg

autoit error reg.jpg

i was solved this problem. just copy AutoitX3.dll to bin directory and it work like a charm.

Share this post


Link to post
Share on other sites

can you please help me, i have the same trouble. added references to dll files, put using statement. but error comes up, it can't find autoit3x dll, whats going on?

Share this post


Link to post
Share on other sites

The DllNotFoundException is caused by screwed up assembly dependencies when the dll package was built.  Nuget installer for AutoitX is not working for the same reason (more details here).  Bottom line - Visual Studio doesn't know it needs to copy AutoItX3.dll to the output directory.  It only copies AutoItX3.Assembly.dll, and forgets about the other one.

The easiest solution is ensuring AutoItX3.dll is in your output bin/Debug or bin/Release directory, when you run your program (basically the same directory as your exe).  You can do that by simply placing AutoItX3.dll in the root of your project in visual studio, and then setting its properties to:

Copy to Output Directory: 'Copy if newer'

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi can someone enlighten me, I have a current application in autoit that calculate IP address. would I be able to port that to c# using autoitx3.dll then that application can be run off the browser. This is fascinating if true

thanks ahead for any answers

Edited by antonioj84

Share this post


Link to post
Share on other sites

I'm not sure what your post is getting at, with "run off the browser".

AutoIt3X allows you to reference the dll in C# and use its functions, which are a subset of AutoIt's native functions.

You wont find UDF functions such as _IE* etc...


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi Johnone,

I understand that part, however I mean in that case can the application run from a IIS server, then user can access thru their browser. I want to be able to use the native udf that come with autoit.

Edited by antonioj84

Share this post


Link to post
Share on other sites

#11 ·  Posted

Thank you very much I was looking for this ^_^

Share this post


Link to post
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

  • Similar Content

    • Luigi
      By Luigi
      Greetings, someone can give a exemple, how send a error from a C#'s dll to AutoIt?
      I use this line, to send an error... but, I want get a error code In AutoIt with macro @error, it's possible?
       
      throw new ArgumentException("arquivo map não existe", "value" ); In this way, work, I know ther are error, but, @errror always is zero.
      I don't want this, I want a number as error code.
      Can you help me?
       
      Best regards
    • ptrex
      By ptrex
      WHAT : is .NET Common Language Runtime (CLR) Framework
      The Common Language Runtime (CLR) is a an Execution Environment . Common Language Runtime (CLR)'s main tasks are to convert the .NET Managed Code to native code, manage running code like a Virtual Machine, and also controls the interaction with the Operating System.
      As part of Microsoft's .NET Framework, the Common Language Runtime (CLR) is managing the execution of programs written in any of several supported languages. Allowing them to share common object-oriented classes written in any of the languages.
      HOW : To access the CLR environment you need to create an Appdomain Object - _CLR_GetDefaultDomain()
      An AppDomain provides an isolated region in which code runs inside of an existing process.
      Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies. Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.
      WHEN : Would you use CLR Runtime Hosts
        1. To access  .NET Class Libraries :
      System System.Collections System.Data System.Drawing System.IO System.Text System.Threading System.Timers System.Web System.Web.Services System.Windows.Forms System.Xml   2. Accessing custom build .Net Assemblies :
        Some Examples (but there are a ton out there)
      AutoItX3 - The .NET Assembly for using AutoItX JSonToXML libr. XMLRPC Libr. .NETPDF libr. .NETOCR Libr WInSCP Libr.  ...   3. To Compile .Net Code into an Assembly
        4. To Run C# or VB.net Code
        5. To Mix AU3 and .Net functionality in your Application
       
      WHERE :  To find documentation about CLR
      First of all you can find a lot on MSDN and here  : Post 4 & Post 6
       
      EXAMPLES : Multiple examples included in Zip !!
      Example : “System.Text.UTF8Encoding”

      Example : “System.IO.FileInfo”

      Example : “System.Windows.Forms”

      Example : AutoItX3 Custom .NET Assembly AutoItX

      Example : Compile Code C# and Code VB

      Example : Compile Code C# at Runtime

       
      WHO : Created the CLR.au3 UDF
      All credits go to : Danyfirex / Larsj / Trancexx  / Junkew
       
      TO DO : The library is still Work in Process …
      (Some of the GUI Controls are not yet working as expected...)
      Anyone is free to participate in contributing to get the bugs resolved and to expand the CLR.au3 functionality ...
      Enjoy !!
      DOWNLOADS :  (Last updated) 
      - added CLR Constants.au3 - Danyfirex
          - Global Constants added (Magic numbers)
      - added .NET CLR CreateObject vs ObjCreate Example.au3 - Junkew
               • 2 approaches give the same result (only valid for COM Visible Assembly)
               • Includes a function that shows you which Assembly Classes are COM Visible
      - added .Net Conventional COM Objects Examples - ptrex
      - added .NET CLR CreateComInstanceFrom Example - Danyfirex
          - You can use it for Regfree COM Assembly Access
          - System.Activator has 4 methods :
              • CreateComInstanceFrom : Used to create instances of COM objects.
              • CreateInstanceFrom : Used to create a reference to an object from a particular assembly and type name.
              • GetObject : Used when marshaling objects.
              • CreateInstance : Used to create local or remote instances of an object.
      - added .NET Access SafeArrays Using AccVarsUtilities Example - LarsJ
      - added SafeArray Utilities functions in Includes - LarsJ 
      - added .NET Access Native MSCorLib Classes - System - ptrex
          Multiple System Class Examples :
               • System.Random
               •  System.DateTime
               •  System.Diagnostics.PerformanceCounter
               •  System.IO.FileInfo
               •  System.Int32
               •  System.Double
               •  System.Speech
               • System.Web
      - added Third Party Assembly Access - ptrex
               • WinSCP : https://winscp.net/eng/download.php
               • IonicZip : http://dotnetzip.codeplex.com/
       
      CLRv3a.zip
      .NET CLR Framework for AutoIT.pdf
    • GTAVLover
      By GTAVLover
      I recently tried to use ControlClick method to send a mouse click command to a button in a application, but I noticed that it is not working when I give first parameter as a window handle (HWND). But, when I give class name or window title, it works fine. I used AutoItX3 and VBScript. 
      Following are the commands I tried in VBScript:
      Dim WINAPI: Set WINAPI = WScript.CreateObject("WinAPIWrapper.WINAPI") Dim AutoItX3: Set AutoItX3 = WScript.CreateObject("AutoItX3.Control") Dim WindowHandle: WindowHandle = WINAPI.WinAPI_FindWindow("my window title", "my window class") 'Window handle obtains fine by my wrapper function 'Above window handle is obtained as a hexadecimal string. (I.E. - 0x00000000) I tried it like: WScript.Echo CStr(AutoItX3.ControlClick(WindowHandle, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(CLng("&h" + Replace(WindowHandle, "0x", "")), "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(0x00000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK Only following commands work: WScript.Echo CStr(AutoItX3.ControlClick("[CLASS:my window class]", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE WScript.Echo CStr(AutoItX3.ControlClick("My window title", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE  
      If any of your suggestions don't work, I will have to write a wrapper function myself to send mouse click commands. I chosen AutoIt V3 because it is good specially when comes to send keystrokes to applications. Please tell me why this won't work when I give window handle as first parameter.
      Thanks in advance.
    • breakbadsp
      By breakbadsp
      AutoIT AU3info doeas not detect all gui objects uniquely for .NET GUIs developed in C#.
      this is not working now i am using COM windows approach for this, But its very difficult.
      Please let me know if anyone has done it before.