Enumerating Explorer shell windows out of memory exception

N

nagar

On certain occasions I get COM exceptions errors when enumerating the
Windows Explorer active windows

Some customers reported the error
System.OutOfMemoryException: Retrieving the COM class factory for
component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due
to the following error: 8007000e.

Here's the code I use to retrieve the list of IE windows. Are there
better solutions that prevent the exceptions?

try {
SHDocVw.ShellWindows shell = new ShellWindowsClass();

int ihandle=handle.ToInt32();
foreach (InternetExplorer ie in shell) {

try {
if (ihandle == ie.HWND) {
path=ie.LocationURL;
}
}
catch (System.Runtime.InteropServices.COMException ex) {

}
catch (System.UnauthorizedAccessException ex) {
}


} catch (FileNotFoundException ex) {
}
catch (System.TypeLoadException ex) {
}
 
W

Walter Wang [MSFT]

Hi nagar,

Several points:

1) If you're only retrieving IE windows, you should cast the item to
IWebBrowser2 first before accessing LocationURL.

2) Please note that using ShellWindows to enumerate IE windows is not
reliable, for example, on Vista, you might not be able to enumerate IE
windows running under protected mode.

I noticed you're testing the handle, could you please tell me more about
your objective or requirement here?

How can I reproduce the issue on my side?


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

nagar

Actually, I want to retrieve the instances of the explorer windows
opened (to get the path of the opened explorer windows).
Is there a reliable way to do that?
I wasn't able to reproduce the problem on my machine but I guess that
the Vista issue could be the cause.
Thanks,
Andrea
 
W

Willy Denoyette [MVP]

Actually, I want to retrieve the instances of the explorer windows
opened (to get the path of the opened explorer windows).
Is there a reliable way to do that?
I wasn't able to reproduce the problem on my machine but I guess that
the Vista issue could be the cause.
Thanks,
Andrea

This shouldn't be an issue on Vista either, as long as you run your code in
the logon session of interactive desktop, running this from a service won't
work on vista.

Willy.
 
W

Walter Wang [MSFT]

Hi Andrea,

So far I'm only aware that retrieving IE instances via ShellWindows might
not be reliable, not mentioned if there's any issues for explorer windows.
Given the nature of this issue that it's not reprodicuble, I think you
might need to contact our Customer Support and Service for further
troubleshooting. Thanks for your understanding.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top