Jump to content

Pass variables from AutoITX C# to au3 script.


Paulliev
 Share

Recommended Posts

Hello,

I have a question. I am making a Windows Form application with C#. I want to automate Chrome, I found out that it won't work properly with AutoITX. So I created a custom AutoIT script and I run it in my C# code. I want to give variables from my C# code to my normal AutoIT and use them there, is that possible? I tried copying a variable to my clipboard in C# and get it in my script, but I don't know how to copy the next variable to my clipboard. See below the code from my C# application.

  private static void AutoItTicket(Ticket ticket1)
        {
            #region Alle variabelen naar notepad exporteren
            
            Clipboard.SetText(ticket1.GetContactPersoon());
            AutoItX.Run(@"C:\Program Files (x86)\AutoIt3\AutoIt3.exe /AutoIt3ExecuteScript setCompany.au3",@"C:\TicketScripts\", 1);
            //Clipboard.SetText(ticket1.GetProbleemOmschrijving());

            #endregion
        }

 

Link to comment
Share on other sites

@Nine Thanks for your answer and sorry for my late reply.

I don't get it working. I need to pass C# variables to my au3 script, but I don't know the syntax. See the code below. for example I want to add $test to the au3 file, how does that look like?

$test = "Dynamic variable"

; Pass $test variable to the setCompany.au3
AutoItX.Run(@"C:\Program Files (x86)\AutoIt3\AutoIt3.exe, /AutoIt3ExecuteScript setCompany.au3", @"C:\TicketScripts\", 1);

Thanks in advance!

Link to comment
Share on other sites

I do not have C#, but I will show you with AutoIt :

Example2()

Func Example2()
  Local $oAutoIt = ObjCreate("AutoItX3.Control")
  Local $var = "This is a test"
  $oAutoIt.Run('"C:\Program Files (x86)\AutoIt3\AutoIt3.exe" /AutoIt3ExecuteScript "C:\Apps\Autoit\Test.au3" ' & _
    '"' & $var & '"', "", $oAutoIt.SW_SHOW)
EndFunc

Test.au3

#include <Constants.au3>

MsgBox ($MB_SYSTEMMODAL, $CmdLine[0], $CmdLine[1])

 

Link to comment
Share on other sites

I'm not experienced with C#, but I can't imagine that it doesn't offer the ability to launch an executable without the use of a 3rd party library. Therefore, I'm confused about why you are trying to use AutoItX to launch an AutoIt script. Why not just use native C# for this?

P.S. Have you looked at the AutoItX help file entry for Run? To me, this command doesn't appear to support parameters.

Link to comment
Share on other sites

here is how you do it. from the master @LarsJ

 

I am not sure if you can do it via the com object mate. I have used the methods below and it works for me.

 

@Nine, you do have .net installed most likely... lol you can use msbuild to build stuff in C# or any .NET language. it's fun! and they have SDKs  too if you really want to develop/debug via Visual Code

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

1 hour ago, Paulliev said:

I've got the AutoITX included in my C#. So it's the other way around

so..., wassup Doc. :) 
Say, why not write an AutoIt script and IPC back and forth with the C# ?. It'll be better than all this AutoItX, as AutoIt has more stuff.  ( my 2 cents. )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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...