如何在不注册的情况下在 .NET (C#) 中使用 AutoItX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6810692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:45:31  来源:igfitidea点击:

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

.netautoitocxregistering

提问by evlo

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

如何在不注册的情况下在 .NET C# 应用程序中使用AutoitXOCX/ ActiveX库)?

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

我想用它创建一个应用程序,而无需使用管理员权限进行安装。

I found some pages on MSDNlike, Registration-Free Activation of COM Components: A Walkthroughabout 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.

我在MSDN上找到了一些页面,例如COM 组件的免注册激活:有关为 DLL 文件创建清单文件的演练。我试过了,没有成功。所以也许这是可能的,但我错误地创建了它。不幸的是,我丢失了 XML 文件,因此无法在此处发布。

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?

是否可以让 AutoItX 在 C# 中工作而无需注册?如果是这样,我该怎么做?

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

我认为应该可以用作 DLL 而不是 OCX,但我不知道如何在 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?

等等。所以如果我要直接调用 DLL,那我该怎么做呢?

回答by Jos van Egmond

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.

在 Visual Studio 的 C# 项目中,只需转到 Reference -> Add Reference -> 浏览到 AutoIt dll 即可。不需要单独注册。但是使用这种方法你必须注册。

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/

更好的方法是使用 [DllImport] 语句直接使用 DLL。这是您可以使用的示例类: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);

回答by Dzmitry Lahoda

Via PInvoke

通过 PInvoke

        var assemblies = new NRegFreeCom.AssemblySystem();
        var module = assemblies.LoadFrom(Path.Combine(Environment.CurrentDirectory, "AutoItX3.dll"));
        var createdDirectly = NRegFreeCom.ActivationContext.CreateInstanceDirectly(module, clsid) as IAutoItX3;
        createdDirectly.Run("Notepad");

Via manifests

通过清单

AutoItX3.dll.manifest:

AutoItX3.dll.manifest:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="AutoItX3.dll" version="3.3.8.1" />
<file name = "AutoItX3.dll">
<comClass
clsid="{1A671297-FA74-4422-80FA-6C5D8CE4DE04}"
threadingModel = "Free" />
<typelib tlbid="{F8937E53-D444-4E71-9725-35B64210CC3B}"
version="1.0" helpdir=""/>
</file>
<comInterfaceExternalProxyStub
name="IAutoItX3"
iid="{3D54C6B8-D283-40E0-8FAB-C97F05947EE8}"
proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
baseInterface="{00000000-0000-0000-C000-000000000046}"
tlbid = "{F8937E53-D444-4E71-9275-35B64210CC3B}" />
</assembly>

AutoItX3Dependency.manifest:

AutoItX3Dependency.manifest:


<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dependency>
<dependentAssembly asmv2:codebase="AutoItX3.dll.manifest">
<assemblyIdentity name="AutoItX3.dll" version="3.3.8.1" type="win32" />
</dependentAssembly>
</dependency>
</asmv1:assembly>

Program.cs Main:

Program.cs 主要内容:


            var createdViaManifest = NRegFreeCom.ActivationContext.CreateInstanceWithManifest(new Guid("{1A671297-FA74-4422-80FA-6C5D8CE4DE04}"), "AutoItX3Dependency.manifest");
            var autoItWithManifest = (IAutoItX3)createdViaManifest;
            autoItWithManifest.Run("Notepad");

Code uses tool for reg free in C# (https://github.com/asd-and-Rizzo/NRegFreeCom). Code snipped from (https://github.com/asd-and-Rizzo/pyautoit)

代码在 C# ( https://github.com/asd-and-Rizzo/NRegFreeCom) 中使用免费注册工具。代码截取自 ( https://github.com/asd-and-Rizzo/pyautoit)

回答by Michele Delle Donne

Copy and paste the AutoItX3.dll file to /bin/Debugor /bin/Releasefolder. Or for Post-build event set the following command line:

将 AutoItX3.dll 文件复制并粘贴到/bin/Debug/bin/Release文件夹。或者对于构建后事件设置以下命令行:

copy /Y "$(SolutionDir)\packages\AutoItX.3.3.12.0\AutoItX3.dll" "$(ProjectDir)\bin\Debug"

 

 

copy /Y "$(SolutionDir)\packages\AutoItX.3.3.12.0\AutoItX3.dll" "$(ProjectDir)\bin\Release"

enter image description here

在此处输入图片说明

An example to upload a file through Windows system window using Firefox as browser. I use AutoItX v3.3.12.0.

使用 Firefox 作为浏览器通过 Windows 系统窗口上传文件的示例。我使用 AutoItX v3.3.12.0。

    /// <summary>
    /// Method which allows you to upload a file through windows system window using firefox as browser
    /// </summary>
    /// <param name="file">path file</param>
    /// <param name="winTitle">Window title</param>
    /// <param name="idEditBox">Text box identifier (es. [CLASS:Edit; INSTANCE:1])</param>
    /// <param name="idBtnLoad">Open button identifier (es. [CLASS:Button; INSTANCE:1])</param>
    /// <returns>void</returns>
    /// <author>Michele Delle Donne</author

    public static void UploadFileByWindowsFireFoxDialog(string file, string winTitle, string idEditBox, string idBtnLoad)
    {

        AutoItX.Init();

        AutoItX.WinWait(winTitle);
        AutoItX.WinActivate(winTitle);

        AutoItX.ControlSetText(winTitle, "", idEditBox, file);
        AutoItX.ControlClick(winTitle, "", idBtnLoad);            
    }

回答by Catur Nugroho

It's very easy. You just need add library from your project. Click right your reference project - Add reference - Browse - Go to location AutoitX3Lib.dll (C:\Program files\AutoitX3\AutoitX\AutoitX3.dll)

这很容易。您只需要从项目中添加库。右键单击您的参考项目 - 添加参考 - 浏览 - 转到位置 AutoitX3Lib.dll (C:\Program files\AutoitX3\AutoitX\AutoitX3.dll)

AutoItX3Lib.AutoItX3 autoit = new AutoItX3Lib.AutoItX3();

For more details visit here

欲了解更多详情,请访问这里