How to use AutoItX in .NET (C#) without registering

evlo picture evlo · Jul 25, 2011 · Viewed 31k times · Source

How do I use AutoitX (OCX/ActiveX library) in a .NET C# application without registering it?

I would like to create an application with it without need to use administrator rights for installation.

I found some pages on MSDN like, Registration-Free Activation of COM Components: A Walkthrough about creating manifest files for DLL files. I tried it and did not succeed. So maybe it is possible and I created it wrongly. Unfortunately I lost the XML files so I can't post it here.

I also tried setting isolated and enable interop types in reference properties without success.

Is it possible to get AutoItX working in C# without need for registering? If so, how do I do it?

I think it should be possible to use as a DLL and not an OCX, but I don't know how exactly to do it in C#.

Currently, I use it like:

AutoItX3Lib.AutoItX3 autoit = new AutoItX3Lib.AutoItX3();
autoit.AutoItSetOption("WinTitleMatchMode", 2);

etc. So if I would go for direct DLL calls, how would I do it then?

Answer

Jos van Egmond picture Jos van Egmond · Jul 25, 2011

In your C# project from Visual Studio, just go to Reference -> Add Reference -> Browse to your AutoIt dll and you're done. There's no need to register it seperately. But using this method you have to register.

A better way is to use the DLL directly, with [DllImport] statements. Here is a sample class that you can use: http://www.autoitscript.com/forum/topic/72905-c-use-of-the-dll-some-idears-for-you/

It defines functions like this:

[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern int AU3_MouseUp([MarshalAs(UnmanagedType.LPStr)] string Button);