2011年4月19日 星期二

[Silverlight]OOB抓取IE並取得SilverlightHost

using (dynamic shellApp = AutomationFactory.CreateObject("Shell.Application"))
{
    dynamic IEObject = null;
    var shellWin = shellApp.Windows();
    for (int i = 0; i < shellWin.Count; i++)
    {
        //MessageBox.Show(shellWin.Item(i).FullName);                        
        if ((shellWin.Item(i).FullName as string).IndexOf("iexplore.exe", StringComparison.OrdinalIgnoreCase) > 0)
        {
            IEObject = shellWin.Item(i);
            //IEObject.navigate("http://www.google.com");
        }
    }
    if (IEObject != null)
    {                        
        MessageBox.Show("IEObject != null");
        //MessageBox.Show(IEObject.Document.GetType().ToString());                        
        
        SilverlightHost sh = IEObject.Document.GetElementById("silverlightControlHost") as SilverlightHost;          
        //MessageBox.Show(IEObject.Document.GetElementById("silverlightControlHost").innerHTML);
    }
}

沒有留言:

張貼留言