I am creating WCF web services
that automatea internet explorer
. There are multiple web service calls that need to access the same instance of Internet Explorer
. However, since the WCF
services are hosted on IIS
all the calls to the web service are executed in session 0. Now to access the same instance of Internet Explorer
I use SHDocVw.InternetExplorer.HWND
property which returns the window handle of an Internet Explorer
instance. In below code when executed as a WCF
service on IIS 7
the window handles always return 0 due to session 0 isolation. Also, I am not able to hook back to the same IE
instance or loop through all the open IE
windows. I can enumerate the process list and find process ids for each IE
window open in session 0, but cannot cast a System.Diagnostics.Process
to SHDocVw.InternetExplorer
object.
Below is my code:
public int GetWhd()
{
InternetExplorer ie = new InternetExplorer();
ie.Visible = true;
return ie.HWND;
}
public int SetWhd(string whd)
{
int wh = Int32.Parse(whd);
InternetExplorer ie = null;
ShellWindows s = new ShellWindows();
foreach (SHDocVw.InternetExplorer ie1 in s)
{
try
{
if (ie1.HWND == wh)
{
ie = ie1;
break;
}
}
catch { return 2; }
}
if (ie != null) { ie.Navigate("www.google.com"); return 1; }
return 0;
}
Any help will be much appreciated.