检索具有clsid {9ba05972-f6a8-11cf-a442-00a0c90a8f39}的组件的com类工厂因以下错误而失败:80040154

时间:2013-09-19 09:26:17

标签: automation remoteapp

我正在尝试自动化ie.This是我的代码来捕捉窗口

ProcessStartInfo psi = new ProcessStartInfo();
            psi.CreateNoWindow = false;
            psi.FileName = "IExplore.exe";
            psi.Arguments = "-nomerge about:blank ";
            psi.WindowStyle = ProcessWindowStyle.Normal;
            Process p = new Process();
            p.StartInfo = psi;

            if (p.Start())
            {
                int maxWait = 10000, wait = 0;
                while (!p.HasExited && (p.MainWindowHandle == IntPtr.Zero))
                {
                    wait += 10;
                    Thread.Sleep(10);
                    p.Refresh();

                    if (wait > maxWait) break;
                }

                wait = 0;
                while (!p.HasExited && (_IE == null))
                {
                    _IE = null;
                    ShellWindows m_IEFoundBrowsers = new ShellWindowsClass();//here i get exception
                    foreach (InternetExplorer Browser in m_IEFoundBrowsers)
                    {
                        if (Browser.HWND == (int)p.MainWindowHandle)
                        {
                            _IE = Browser;
                            break;
                        }
                    }

                    if ((_IE != null) || (wait > maxWait)) break;
                    else
                    {
                        wait += 10;
                        Thread.Sleep(10);
                    }
                }

                if (_IE != null)
                {
                    IE.Visible = true;
                    IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
                }
                else
                {
                    Console.WriteLine("Problem opening IE!");
                }
            }

这段代码工作正常,但是当我尝试通过remoteapp启动应用程序时,我得到了异常,我猜是理由是一些访问相关但不确定要做什么。请帮忙

1 个答案:

答案 0 :(得分:1)

最后让它工作只需用小的替换上面的大代码

**

_IE = new InternetExplorer();
                IE.Visible = true;
                IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
                var handle = GetConsoleWindow();
                ShowWindow(handle, SW_HIDE);

**

但是,如果自动化失败并且因为卡住然后休息所有自动化将开始抛出此异常,我也会遇到异常。对此的解决方案是我需要关闭失败的实例,即从任务管理器,然后所有将再次正常工作。