2011-07-25 71 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);    
    } 
相關問題