Reputation: 31
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
Upvotes: 0
Views: 985
Reputation: 31
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.
Upvotes: 1