retrieving the com class factory for component with clsid {9ba05972-f6a8-11cf-a442-00a0c90a8f39} failed due to following error:80040154

StackOverflow https://stackoverflow.com/questions/18890945

  •  29-06-2022
  •  | 
  •  

Question

I am trying to automate ie.This is my code to catch ie window

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!");
                }
            }

This code works fine normally but when i try to launch application via remoteapp then i get exception i guess reason is some access related but nt sure wht to do. please help

Was it helpful?

Solution

Finally got it working just replace above big code with small one

**

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

**

But here also i get above exception if automation failed and ie gets stuck then rest all automation will start throwing this exception. The resolution to that is i need to close the instance of failed ie from taskmanager then all will work fine again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top