less than 1 minute read

Ruby環境でのAutoItの使い方をまとめる。

環境

  • Ruby 3.1.4
  • Bundler 2.4.13

インストール

dllのインストール

> autoit install

以下のエラーとなる。

> bundle exec irb      
irb(main):001:0> require 'autoit'
=> true
irb(main):002:0> control = AutoIt::Control.new
C:/Users/kanek/.local/share/gem/ruby/3.1.0/gems/autoit-1.3.4/lib/autoit/control.rb:12:in `initialize': failed to create WIN32OLE object from `AutoItX3.Control' (WIN32OLERuntimeError)
    HRESULT error code:0x80040154
      Class not registered
        from C:/Users/kanek/.local/share/gem/ruby/3.1.0/gems/autoit-1.3.4/lib/autoit/control.rb:12:in `new'
        from C:/Users/kanek/.local/share/gem/ruby/3.1.0/gems/autoit-1.3.4/lib/autoit/control.rb:12:in `initialize'
        from (irb):2:in `new'
        from (irb):2:in `<main>'
        from C:/app/lang/ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
        from C:/app/lang/ruby/Ruby31-x64/bin/irb:33:in `load'
        from C:/app/lang/ruby/Ruby31-x64/bin/irb:33:in `<main>'

Windows 64bit環境だと上手くいかず、下記コマンドで64bit用のDLLを直接インストールしたところ成功した。

> cd %USERPROFILE%\.local\share\gem\ruby\3.1.0\gems\autoit-1.3.4\vendor
> register64.bat AutoItX3_x64.dll