IronRubyでもUIAutomation出来ない……

PowerShellで挫折したので、IronRubyで同じような事が出来るか挑戦。ClrStringとStringを比較すると必ずfalseになるとか、Namespaceを省略して書く方法がわからん、とかを乗り越えてボタンを押せそうなところまで行ったのですが、やっぱり、だめだった……。

require 'mscorlib'  
require 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationClient.dll'
require 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationTypes.dll'

puts System::Threading::Thread.CurrentThread.GetApartmentState().ToString()

$auto = System::Windows::Automation

def gc(element, name)
  element.FindAll($auto::TreeScope.Children, $auto::Condition.TrueCondition).detect { | el | el.Current.ClassName.to_str == name }
end

gc(gc($auto::AutomationElement.RootElement, 'SciCalc'), 'Button').GetCurrentPattern($auto::InvokePattern.Pattern).Invoke

日本語の比較もうまくいかなかったので、クラス名で要素を取得するように変えてます。SciCalc(電卓Windowのクラス)の下にある、最初のButtonクラスを取得するんですが、実行すると


PS > rbx auto.rb
STA
UIAutomationClient:0:in `GetCurrentPattern': サポートされていないパターンです。 (TypeError)
from Snippets:0:in `main'
from Snippets:0:in `Initialize'PS >
アパートメントもSTAであるっぽいのに失敗するので、やっぱ何か別の原因なのだろうか……。