它看起來像一個已知的在.NET包裝本地UIAutomationCore.dll(是的,它的核心不是.NET)的bug。它包含在WinVista +中(.NET Framework也將它添加到WinXP中)。
這是一個C# example如何使用來自C#的原生COM API(UIAutomationCore.dll
)。這裏只是複製代碼:
using System;
using interop.UIAutomationCore;
namespace PrintDesktopUiaElementNameViaCom
{
class PrintDesktopUiaElementNameViaComProgram
{
static void Main(string[] args)
{
// Instantiate the UIA object:
IUIAutomation _automation = new CUIAutomation();
// Get the root element
IUIAutomationElement rootElement = _automation.GetRootElement();
// Get its name
string rootName = rootElement.CurrentName;
Console.WriteLine(
"The root automation element's name should be 'Desktop'.");
Console.WriteLine("The actual value is: '{0}'", rootName);
}
}
}