"C#怎么遍历IE窗体"出现拒绝访问错误
引用System32中SHDocVw.dll和Shell32.dll
C# code
private void Form1_Load(object sender, EventArgs e)
{
Shell32.ShellClass shell = new Shell32.ShellClass();
SHDocVw.ShellWindows windows = shell.Windows() as SHDocVw.ShellWindows;
string[] lines = new string[windows.Count];
for (int i = 0; i < windows.Count; i++)
{
SHDocVw.ShellBrowserWindow win = windows.Item(i) as SHDocVw.ShellBrowserWindow;
lines[i] = win.LocationName;
}
memoEdit1.Lines = lines;
}
有一个IE窗口(别的都可以)获取时就出现0x80070005错误,不知何故。难道跟权限有关?我的机器处于公司局域网中。这个网页是立思辰的打印管理窗口。跟是否跨域访问无关。
用以下语句:
SHDocVw.ShellWindowsClass shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
//if it is ie window
if (ie.FullName.ToUpper().IndexOf("IEXPLORE.EXE") > 0)
{
.......................
则不会出错,但是连这个窗口都找不着,就好像这个窗口对这个语句 foreach (SHDocVw.InternetExplorer ie in shellWindows)是隐身的。