Jump to content
daluu

Using AutoIt in VB.NET

Recommended Posts

daluu

This is a repost from http://www.d3scene.com/forum/development/82572-tutorial-use-autoit-vb-net.html that I came across today. I don't think it is cross posted here already doing a search for .NET related stuff here. Please move to appropriate forum if posted to wrong one (e.g. ActiveX/COM Help and Support (AutoItX) or General Help and Support). If already duplicated here, please delete.

Thought it deserves a copy here w/o having users to register over at the source forum to see it. I've yet to personally try the example though, plan to soon. Perhaps a good idea to later on provide the C# version of code snippet for comparison purposes.

Original post info modified for clarity:

 

In this tutorial you will learn how to use Autoit functions in VB.NET(and C#)

 
Things you need :
 
Microsoft Visual Basic.NET(or C#) 2010 Express (or any other versions)
AutoitX Library which is in attachments
 
Create a new (VB).NET project (e.g. Windows Forms Application) and add a button in your form
Go to your project references and add AutoitX Library
Now go to your form and add a button
Go to codes section and fill in sample code below to create a button that will launch notepad.exe then enter text into it and finally close notepad as a demo.
 
Now test your program, you will see the exciting result
 
Q.Whats the point of using Autoit in VB.NET ?
A.As you know Autoit is single threaded, but when you use it in another language like VB.NET you can use all .NET API's combine Autoit functions with Multi threading support,using microsoft visual form designer and ... (a lot of others!)
 
Imports AutoItX3Lib

Public Class MainForm
    Dim AutoitCommand As New AutoItX3

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
   AutoitCommand.Run("notepad.exe")
       AutoitCommand.WinWait("Untitled - Notepad")
       AutoitCommand.Send("This text sent to notepad by autoit functions{ENTER}Have Fun")
       AutoitCommand.Sleep(1000)
       AutoitCommand.WinKill("Untitled - Notepad")
       End
    End Sub
End Class

AutoItX3_x86.rar

AutoItX3_x64.rar

  • Like 1

Share this post


Link to post
Share on other sites
kcvinu

Hi 

daluu, Although the code above is not working for me, but i was shocked because, this is what i wanted. Thanks a lot.  I have tested lot of other functions. All are working. except this. May be my notepad is the problem. And i can only see a few autoit functions in vb.net. Where are the others ?. Please tell me that what should i do with AutoItX3_x86.rar file. 

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
kcvinu

Hi 

daluu

Please tell me how to tie up this AutoitX with Python.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
kcvinu

Hi daluu, 

I am almost there, but i need ProgID or CLSID of autoitX3. How to find it


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
kcvinu

Hi daluu,

It worked. Thanks a lot. An artcle in that link says that every info about COM in python is in Oreilly's Python Programming on Win32

by Mark Hammond. I have that book. After reading that chapter, i can easily connect AutoIt COM in python. Thanks a lot.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
TheDcoder

What am I seeing here :shocked:, Using AutoItX COM Library in VB.NET instead of using VB.NET's own abilities :think:?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
cyxstudio

sorry if i bumped an old thread, but why does my anti virus flag this as a virus, it 

autoitKMS.png

Share this post


Link to post
Share on other sites
TheDcoder

AutoKMS is a program used to crack Windows... Not related to this thread I guess...

Edited by TheDcoder

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
cyxstudio
On 12/23/2017 at 2:32 PM, TheDcoder said:

AutoKMS is a program used to crack Windows... Not related to this thread I guess...

nope it flagged the download as virus

download as in the autoit library dll. which is the file attached in original post.

Share this post


Link to post
Share on other sites
TheDcoder

AutoIt is known for false positives, but I don't think it would be flagged as AutoKMS, you can click on "Show Details" and look at the location of the file, can you confirm that it is indeed the library?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
cyxstudio
18 minutes ago, TheDcoder said:

AutoIt is known for false positives, but I don't think it would be flagged as AutoKMS, you can click on "Show Details" and look at the location of the file, can you confirm that it is indeed the library?

so theres nothing for me to be worried about?

Yes it is the dll file attached in the main post triggered my anti virus

My windows defender identified it as Trojan.Win32/spursint.F!cl

Anyway i went to my autoit folder and found AutoItX3.dll under AutoitX, its pretty much the same thing am i right? I can import that as reference into my visual studio?

Share this post


Link to post
Share on other sites
TheDcoder
11 minutes ago, cyxstudio said:

My windows defender identified it as Trojan.Win32/spursint.F!cl

Well, it is different from the AutoKMS detection from your screenshot.

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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

    • IgImAx
      By IgImAx
      Hi
       
      UPDATED Notes: ===============================================================================
      UPDATED: My main and second questions answered. Here the answers:
      To add/access WinMenuSelectItem you need to [Thanks to Fernando_Marinho]: Add AutoItX.Dotnet in Manage NuGet Packages Right Click in your Project -> Add -> Reference... -> COM ( Type Libraries )than, check the option AutoItX3 1.0 Type Library  using AutoItX3Lib; AutoItX3 au3 = new AutoItX3(); au3.WinMenuSelectItem("", ...) My full source code in C# exists in 11 posts in below. How to access those overloaded methods in AutoitX3 that are not accessible via above method!? Or how to fix AutoitX3 DLL Registration need in target computers without Autoit pre-installed on them!? Please check my post at 14 posts below!
      =============================================================================== Original Post:
       
       
      I was writing a small app in Autoit to close µTorrent app. It was working. Then I try to import AutoItX into C#, but unfortunately this method
      WinMenuSelectItem Couldn't find by IntelliSense and If I typed completely it still give me this message:
      Please check the image. I Google it and I found this QA at stackoverflow: Autoit error within C# application I saw they use this line:
      au = new AutoItX3Lib.AutoItX3Class(); I figure it how to add 'AutoItX3Lib' to project (by adding 'AutoItX3.dll' to reference) but again! When I use this line:
      var au = new AutoItX3Class(); I got this error message: Interop type 'AutoItX3Class' cannot be embedded. Use the applicable interface instead.
      My system info:
      Visual Studio 2017 Enterprise - v15.5.4
      X64 Windows 10 Enterprise 1607
      Thanks in advanced
      IgImAx

    • JLogan3o13
      By JLogan3o13
      Not one usually to post non-AutoIt things, but as I have this question on StackExchange I thought I would throw it up here as well for any of our C# folks:
      I currently have an AutoIt GUI that calls a powershell script; the intent is to allow low-level technicians to batch create VMs in vSphere. Due to some changes in requirements from the customer, I am re-writing as a wpf app. The app itself is complete and working; this is more of a curiosity question.
      I have two methods attached to buttons on the GUI - one to pull all the data out of a listview and export to csv and another to do the reverse; importing from csv to the listview element. I wrote the export first, and went with manipulating the Excel application:
      private void Launch(object sender, RoutedEventArgs e) { Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application(); oExcel.Visible = true; Microsoft.Office.Interop.Excel.Workbook oWorkBook = oExcel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet); Microsoft.Office.Interop.Excel.Worksheet oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oExcel.ActiveSheet; int row = 2; //allow for header row int column = 1; oSheet.Cells[1, 1] = "Name"; oSheet.Cells[1, 2] = "CPU"; oSheet.Cells[1, 3] = "RAM"; oSheet.Cells[1, 4] = "IP Address"; oSheet.Cells[1, 5] = "Subnet Mask"; oSheet.Cells[1, 6] = "Port Group"; oSheet.Cells[1, 7] = "Default Gateway"; oSheet.Cells[1, 8] = "DNS"; oSheet.Cells[1, 9] = "Description"; oSheet.Cells[1, 10] = "Template"; oSheet.Cells[1, 11] = "Host"; oSheet.Cells[1, 12] = "Site"; oSheet.Cells[1, 13] = "Folder"; oSheet.Cells[1, 14] = "DataStore"; oSheet.Cells[1, 15] = "Patch Method"; oSheet.Cells[1, 16] = "HDD1Size"; oSheet.Cells[1, 17] = "HDD1Format"; oSheet.Cells[1, 18] = "HDD2Size"; oSheet.Cells[1, 19] = "HDD2Format"; oSheet.Cells[1, 20] = "HDD3Size"; oSheet.Cells[1, 21] = "HDD3Format"; oSheet.Cells[1, 22] = "HDD4Size"; oSheet.Cells[1, 23] = "HDD4Format"; oSheet.Cells[1, 24] = "HDD5Size"; oSheet.Cells[1, 25] = "HDD5Format"; foreach (var oVM in MyItems) { oSheet.Cells[row, column] = oVM.Name; oSheet.Cells[row, (column + 1)] = oVM.CPU; oSheet.Cells[row, (column + 2)] = oVM.RAM; oSheet.Cells[row, (column + 3)] = oVM.IP; oSheet.Cells[row, (column + 4)] = oVM.Subnet; oSheet.Cells[row, (column + 5)] = oVM.PortGroup; oSheet.Cells[row, (column + 6)] = oVM.Gateway; oSheet.Cells[row, (column + 7)] = oVM.DNS; oSheet.Cells[row, (column + 8)] = oVM.Description; oSheet.Cells[row, (column + 9)] = oVM.Template; oSheet.Cells[row, (column + 10)] = oVM.Host; oSheet.Cells[row, (column + 11)] = oVM.Site; oSheet.Cells[row, (column + 12)] = oVM.Folder; oSheet.Cells[row, (column + 13)] = oVM.Datastore; oSheet.Cells[row, (column + 14)] = oVM.Patch; oSheet.Cells[row, (column + 15)] = oVM.HDD1Size; oSheet.Cells[row, (column + 16)] = oVM.HDD1Format; oSheet.Cells[row, (column + 17)] = oVM.HDD2Size; oSheet.Cells[row, (column + 18)] = oVM.HDD2Format; oSheet.Cells[row, (column + 19)] = oVM.HDD3Size; oSheet.Cells[row, (column + 20)] = oVM.HDD3Format; oSheet.Cells[row, (column + 21)] = oVM.HDD4Size; oSheet.Cells[row, (column + 22)] = oVM.HDD4Format; oSheet.Cells[row, (column + 23)] = oVM.HDD5Size; oSheet.Cells[row, (column + 24)] = oVM.HDD5Format; row++; } oExcel.Application.ActiveWorkbook.SaveAs(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\example", 6); } It works, but it is slow. I have Excel set to visible for testing, and it is a good 6 or 7 seconds on a pretty high end box before the app even pops up.  It then takes another 2 seconds to populate 11 rows (this could be in the hundreds of rows at some point).
      I then wrote the code for the reverse, and decided to try a StreamReader object. The result, surprisingly, was almost immediate:
      OpenFileDialog xls = new OpenFileDialog(); xls.Multiselect = false; xls.Filter = "CSV files (*.csv)|*.csv"; xls.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); xls.ShowDialog(); string ins; if (xls.FileName != null) { FileStream srcFS; srcFS = new FileStream(xls.FileName, FileMode.Open); StreamReader srcSR = new StreamReader(srcFS, System.Text.Encoding.Default); do { ins = srcSR.ReadLine(); if (ins != null) { string[] parts = ins.Split(','); MyItems.Add(new MyItem { Name = parts[0], CPU = parts[1], RAM = parts[2], IP = parts[3], Subnet = parts[4], PortGroup = parts[5], Gateway = parts[6], DNS = parts[7], Description = parts[8], Template = parts[9], Host = parts[10], Site = parts[11], Folder = parts[12], Datastore = parts[13], Patch = parts[14], HDD1Size = parts[15], HDD1Format = parts[16], HDD2Size = parts[17], HDD2Format = parts[18], HDD3Size = parts[19], HDD3Format = parts[20], HDD4Size = parts[21], HDD4Format = parts[22], HDD5Size = parts[23], HDD5Format = parts[24] }); } } while (ins != null); srcSR.Close(); } }  
      So, I thought I would go back and change the export to use the same method:
      FileStream srcFS; srcFS = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\testingout.csv", FileMode.CreateNew, FileAccess.Write); StreamWriter srcWrt = new StreamWriter(srcFS, System.Text.Encoding.Default); StringBuilder header = new StringBuilder(); header.Append("Name").Append(',') .Append("CPU").Append(',') .Append("RAM").Append(',') .Append("IP Address").Append(',') .Append("Port Group").Append(',') .Append("Default Gateway").Append(',') .Append("DNS").Append(',') .Append("Description").Append(',') .Append("Template").Append(',') .Append("Host").Append(',') .Append("Site").Append(',') .Append("Folder").Append(',') .Append("Datastore").Append(',') .Append("Patch").Append(',') .Append("HDD1Size").Append(',') .Append("HDD1Format").Append(',') .Append("HDD2Size").Append(',') .Append("HDD2Format").Append(',') .Append("HDD3Size").Append(',') .Append("HDD3Format").Append(',') .Append("HDD4Size").Append(',') .Append("HDD4Format").Append(',') .Append("HDD5Size").Append(',') .Append("HDDFormat").Append(','); srcWrt.WriteLine(header); foreach (MyItem item in MyItems) { StringBuilder builder = new StringBuilder(); builder.Append(item.Name).Append(',') .Append(item.CPU).Append(',') .Append(item.RAM).Append(',') .Append(item.IP).Append(',') .Append(item.Subnet).Append(',') .Append(item.PortGroup).Append(',') .Append(item.Gateway).Append(',') .Append(item.DNS).Append(',') .Append(item.Description).Append(',') .Append(item.Template).Append(',') .Append(item.Host).Append(',') .Append(item.Site).Append(',') .Append(item.Folder).Append(',') .Append(item.Datastore).Append(',') .Append(item.Patch).Append(',') .Append(item.HDD1Size).Append(',') .Append(item.HDD1Format).Append(',') .Append(item.HDD2Size).Append(',') .Append(item.HDD2Format).Append(',') .Append(item.HDD3Size).Append(',') .Append(item.HDD3Format).Append(',') .Append(item.HDD4Size).Append(',') .Append(item.HDD4Format).Append(',') .Append(item.HDD5Size).Append(',') .Append(item.HDD5Format); srcWrt.WriteLine(builder); } MessageBox.Show("Task Complete"); What surprised me is this method is exponentially slower; on the order of 40 seconds to return the MsgBox. I also noticed that even though the loop is complete and shows the message, is seems the stream is still writing. If I open the file too quickly it shows that it is still in use by "Another User". So by the time the file is available to me it is actually closer to a minute for an 11-line csv.
      I'm just curious at the difference in speed read vs write using FileStream. Is it something I borked on implementation (eminently possible) or is this a known issue? If interacting with Excel is the way to go (not ideal) is there something I could do to shorten the initial lag?
    • Earthshine
      By Earthshine
      This baby can do almost any language! I found Gleany on this site and set it up on a fresh win10 install. all i would need to do to make it build an exe of the search files app we discovered is the .NET Target Framework download to build 100 % but the exe works and generates! You also need to add the path the the version of csc.exe that you want to run. MSBuild is part of .NET and can read your .csproj file.
      YOU can develop .NET OR C/C++ on this baby!
      Super lightweight (fit for crappy laptops), and you can use any dev compilers you wish, Ming, MS, etc, whatever.
      To use the build, you need to open the csproj file, else, to check your syntax it can compile individual files as well. The warning are because I do not have the .NET 4.6 Targeting Pack installed... LOL, and I could get rid of the Core warning, yes, I did not want to build a .NET Core.dll I wanted a live x64 exe! Told you MSBUILD could handle .CSPROJ, .VBPROJ, and all others Microsoft. Don't let Visual Code or Visual Studio slow you down, although, this works with Visual Code as well but there is only debugging in CORE.DLL projects

      ListFiles Example.zip
       

    • 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
×