24

如何在 .NET C# 应用程序中使用AutoitXOCX / ActiveX库)而不注册它?

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

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

我还尝试在引用属性中设置隔离并启用互操作类型,但没有成功。

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

我认为应该可以用作 DLL 而不是 OCX,但我不知道如何在 C# 中准确地做到这一点。

目前,我像这样使用它:

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

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

4

4 回答 4

9

在 Visual Studio 的 C# 项目中,只需转到 Reference -> Add Reference -> Browse to your AutoIt dll,就完成了。无需单独注册。但是使用这种方法你必须注册。

更好的方法是直接使用 DLL,并带有 [DllImport] 语句。这是您可以使用的示例类:http ://www.autoitscript.com/forum/topic/72905-c-use-of-the-dll-some-idears-for-you/

它定义了这样的函数:

[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern int AU3_MouseUp([MarshalAs(UnmanagedType.LPStr)] string Button);
于 2011-07-25T14:05:42.177 回答
8

通过 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");

通过清单

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:


<?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 主要:


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

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

于 2013-11-15T08:13:54.623 回答
0

将 AutoItX3.dll 文件复制并粘贴到/bin/Debug/bin/Release文件夹中。或为 Post-build 事件设置以下命令行:

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"

在此处输入图像描述

使用 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);            
    }
于 2017-07-13T15:23:54.300 回答
-1

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

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

有关更多详细信息,请访问此处

于 2013-04-13T12:05:44.803 回答