Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2006, 10:57 PM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default Accessing Internet Explorer instance parentWindow

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/
__________________
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer cannot open the internet site cathiec ASP.NET 2.0 Basics 1 October 22nd, 2005 01:30 PM
Internet Explorer JelfMaria VB How-To 10 April 27th, 2005 03:58 PM
scrollTo on Internet Explorer rpalanivelu HTML Code Clinic 2 September 2nd, 2004 06:12 AM
Internet Explorer Issue wndy26 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 23rd, 2004 11:11 PM
Closing Internet Explorer mahulda ASP.NET 1.0 and 1.1 Basics 1 April 7th, 2004 08:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.