我正在创建WCF web services自动化internet explorer.有多个Web服务调用需要访问同一个实例Internet Explorer.但是,由于WCF服务托管在IISWeb服务的所有调用都在会话0中执行.现在访问Internet ExplorerI use 的同一个实例,SHDocVw.InternetExplorer.HWND它返回Internet Explorer实例的窗口句柄.在下面的代码中,作为窗口WCF上IIS 7的服务执行句柄时,由于会话0隔离,总是返回0.此外,我无法挂钩到同一个IE实例或循环所有打开的IE窗口.我可以枚举进程列表并查找IE在会话0中打开的每个窗口的进程ID ,但不能转换System.Diagnostics.Process为SHDocVw.InternetExplorer对象.
以下是我的代码:
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) …Run Code Online (Sandbox Code Playgroud)