Hi all,
I'm trying to get access to the execScript() method of a running Internet Explorer instance using C#. I have run aximp on SHDocVw.dll and use both it and mshtml as references in the project. I am able to get an instance of IE and then an instance of the HTMLDocument object, but when I try to access parentWindow, I get this error:
Code:
System.Runtime.InteropServices.COMException (0x80040154): Class not registered
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at mshtml.HTMLDocumentClass.get_parentWindow()
at TestIEApp.Class1.Main(String[] args) in e:\visual studio projects\testieapp\class1.cs:line 31
The code I use looks like this:
Code:
using System;
using mshtml;
using SHDocVw;
namespace TestIEApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ShellWindowsClass sws = new ShellWindowsClass();
System.Console.WriteLine("There are {0} instances of IE running.", sws.Count);
foreach(InternetExplorer ie in sws)
{
try
{
HTMLDocument doc = (HTMLDocument) ie.Document;
System.Console.WriteLine("IE Instance: " + doc.title);
try
{
doc.parentWindow.alert("hi");
}
catch (Exception ex)
{
System.Console.WriteLine(ex.ToString());
}
}
catch (Exception ex)
{
System.Console.WriteLine("Not IE");
}
}
System.Console.ReadLine();
}
}
}
Does anyone have any idea why this happening and how I can workaround it?
Thanks.
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/