2011-07-25 30 views
22

如何在.NET C#应用程序中使用AutoitXOCX/ActiveX库),而无需注册?如何在.NET(C#)中使用AutoItX而无需注册

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

我在MSDN上发现了一些页面,Registration-Free Activation of COM Components: A Walkthrough关于为DLL文件创建清单文件。我试过了,没有成功。所以也许这是可能的,我错误地创造了它。不幸的是我丢失了XML文件,所以我不能在这里发布。

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

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

我认为它应该可以用作DLL而不是OCX,但我不知道在C#中如何完成它。

目前,我用它喜欢:

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

等。所以,如果我会去直接DLL调用,我将如何做到这一点呢?

回答

8

在从Visual Studio C#项目,只要去参考 - >添加引用 - >浏览到您的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); 
+1

特别是如果你正在使用的AutoIt 3.3,那么你要在这个岗位类别 - http://www.autoitscript.com/forum/topic/72905-c-use-of-the-dll-some -idears-for-you /#entry642195 –

-1

这很容易。你只需要从你的项目中添加库。点击右侧的参考项目 - 添加引用 - 浏览 - 转到位置AutoitX3Lib.dll(C:\ Program Files文件\ AutoitX3 \ AutoitX \ AutoitX3.dll)

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

详情visit here

+2

但是这种方法要求在正在部署软件的计算机上注册'AutoItX'。它没有解决注册问题。 –

5

通过的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)REG免费。 从(https://github.com/asd-and-Rizzo/pyautoit)删除的代码

0

将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

一个例子上传使用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);    
    } 
相关问题