1

I'm trying to use autoit with Java so I added jacob jar and autoitX4 to my project.But I got this error :

'Exception in thread "main" com.jacob.com.ComFailException: Can't co-create object
    at com.jacob.com.Dispatch.createInstanceNative(Native Method)
    at com.jacob.com.Dispatch.<init>(Dispatch.java:101)
    at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
    at autoitx4java.AutoItX.<init>(AutoItX.java:231)
    at net.java.dev.jna.step2_2.Test.main(Test.java:14)'

Here is my current code :

import java.io.File;
import com.jacob.com.LibraryLoader;
import autoitx4java.AutoItX;
import junit.framework.Assert;
public class Test {
    public static void main(String[] args) {
        File file = new File("./src/test/ressources//jacob-1.17-M2-x64.dll"); // path
        System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
        AutoItX x = new AutoItX();
        String notepad = "Untitled - Notepad";
        String testString = "this is a test.";
        x.run("notepad", "C:/Windows/System32", AutoItX.SW_MAXIMIZE);
        x.winActivate(notepad);
        x.winWaitActive(notepad);
        x.send(testString);
        Assert.assertTrue(x.winExists(notepad, testString));
        x.winClose(notepad, testString);
        x.winWaitActive("Notepad");
        x.send("{ALT}n");
        Assert.assertFalse(x.winExists(notepad, testString));
    }
}

could someone help me please I can't fix the error

Asma
  • 29
  • 10

1 Answers1

0

Recently I also had the same issue and got this fixed with below solution.
Step1. Downloaded and re-installed recent version of Autoit for 64-bit. i.e. Using 'AutoIt Full Installation' version from below link.

    https://www.autoitscript.com/site/autoit/downloads/

Step2. Downloaded recent version of Jacob from below link:

    https://sourceforge.net/projects/jacob-project/

Step3. Placed the '.jar' and '.dll' files as below:

    C:\Program Files\Java\jdk1.8.0_191\bin\Jacob.jar
    C:\Program Files\Java\jdk1.8.0_191\bin\Jacob-1.19-X64.dll

    D:\Eclipse Workspace\ProjectFolder\lib\AutoitX4Java.jar
    D:\Eclipse Workspace\ProjectFolder\lib\Jacob.jar
    D:\Eclipse Workspace\ProjectFolder\lib\Jacob-1.19-X64.dll

    D:\Eclipse Workspace\ProjectFolder\lib\Tools\AutoitX3.dll

Step4. Registered the AutoItX3.dll through command prompt (open cmd prompt as an administrator)

c:\Windows\system32> regsvr32 "D:\Eclipse Workspace\ProjectFolder\lib\tools\AutoItX3.dll"

That's it!

As per my setup, the path for jacob dll, in the code is

File file = new File("lib", jacob-1.18-x64.dll);

Hope this helps.

Deepali
  • 11
  • 1