在C#中自动化Internet Explorer的外部实例 [英] Automating external instances of Internet Explorer in C#

查看:105
本文介绍了在C#中自动化Internet Explorer的外部实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从正在运行的Internet Explorer实例接收事件。

到目前为止,我只能从我启动的实例接收事件

代码,但我需要从所有正在运行的Internet实例接收事件

资源管理器(我的意思是用户自己启动的那些)。


我知道这是可能的,因为我在三个月前做过。不幸的是,我不能找到代码。
找不到代码。我已经看过所有关于

自动化Internet Explorer的微软文章,所以请不要推荐这些链接。


提前致谢

I''m trying to receive events from a running instance of Internet Explorer.
So far I''ve only been able to receive events from an instance I launch from
code, but I need to receive events from all running instances of Internet
Explorer (I mean those that the user launches himself).

I know this is possible because I did it three months ago. Unfortunately, I
can''t find the code. I''ve already looked at all the Microsoft articles on
automating Internet Explorer, so please don''t suggest those links.

Thanks in advance.

推荐答案

您好,


感谢您的帖子。据我了解,您希望连接到正在运行的Internet Explorer的

实例。如果是这样,请参阅知识库文章176792.


HOWTO:连接到Internet Explorer的运行实例
http://support.microsoft.com/?id=176792


希望这个帮助。


问候,


HuangTM

微软在线合作伙伴支持

MCSE / MCSD


安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有授予任何权利。

Hello,

Thanks for your post. As I understand, you want to connect to a running
instance of Internet Explorer. If so, please refer to the KB article 176792.

HOWTO: Connect to a Running Instance of Internet Explorer
http://support.microsoft.com/?id=176792

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


谢谢,但我已经看过这篇文章,正如所有其他微软文章那样
$ b处理连接到Internet Explorer的$ b。


在本文中,我的代码循环通过ShellWindows并获得每个正在运行的实例的

引用Internet Explorer。这就是我在哪里连接到IE事件,但是他们根本就没有开火。

静态私人SHDocVw.ShellWindows shellWindows = new

SHDocVw.ShellWindowsClass();

静态私有SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHan dler

beforeNavigate2;

static private SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler newWindow2;


public static void Main()

{

foreach(SHDocVw.InternetExplorer,即在shellWindows中)

{

MessageBox.Show(" ie.Location:" + ie.LocationURL);

ie.BeforeNavigate2 + = beforeNavigate2;

ie.NewWindow2 + = newWindow2;

}

}


消息框显示URL,但事件只是'好了。


田敏黄 < TI ****** @ online.microsoft.com>在消息中写道

news:uO ************** @ cpmsftngxa07.phx.gbl ...
Thanks, but I''ve already seen this article, as all other Microsoft articles
that deal with connecting to Internet Explorer.

As in this article, I have code that cycles through ShellWindows and gets a
reference to each running instance of Internet Explorer. That''s where I
connect to the IE events, but they simply don''t fire.
static private SHDocVw.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass();
static private SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHan dler
beforeNavigate2;
static private SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler newWindow2;

public static void Main()
{
foreach(SHDocVw.InternetExplorer ie in shellWindows)
{
MessageBox.Show("ie.Location:" + ie.LocationURL);
ie.BeforeNavigate2 += beforeNavigate2;
ie.NewWindow2 += newWindow2;
}
}

The message box displays the URL, but the events simply don''t fire.

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:uO**************@cpmsftngxa07.phx.gbl...
你好,
感谢您的帖子。据我了解,您希望连接到正在运行的Internet Explorer实例。如果是这样,请参阅知识库文章
176792.
HOWTO:连接到Internet Explorer的运行实例
http://support.microsoft.com/?id=176792
希望这会有所帮助。

HuangTM
Microsoft在线合作伙伴支持
MCSE / MCSD

获得安全保障! - www.microsoft.com/security
此帖子已提供按原样没有保证,也没有授予任何权利。
Hello,

Thanks for your post. As I understand, you want to connect to a running
instance of Internet Explorer. If so, please refer to the KB article 176792.
HOWTO: Connect to a Running Instance of Internet Explorer
http://support.microsoft.com/?id=176792

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



您好,


感谢您的回复。根据我的研究,我能够收到我身边的IE

活动。我现在与您分享以下信息:


1.您需要创建一个WinForm应用程序而不是Console

应用程序。

2.我查看了你的代码,似乎代表没有映射到

方法。请参考以下代码片段:


// -------------- code snippet ------------ ----------

公共类Form1:System.Windows.Forms.Form

{

静态私有SHDocVw。 ShellWindows shellWindows = new

SHDocVw.ShellWindowsClass();


public Form1()

{

InitializeComponent();


foreach(SHDocVw.InternetExplorer,即在shellWindows中)

{

MessageBox.Show(" ie) .Location:" + ie.LocationURL);

ie.BeforeNavigate2 + = new

SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHan dler(this.ie_BeforeNavigat

e2 );

}


public void ie_BeforeNavigate2(object pDisp,ref object url,ref

object Flags,ref object TargetFrameName, ref对象PostData,ref对象

Headers,ref bool取消)

{

MessageBox.Show(" event received!");

}

// --------------- --------- of ----------------------------


请在您身边查看。


祝你有愉快的一天!


问候,


HuangTM

Microsoft在线合作伙伴支持

MCSE / MCSD


安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有赋予任何权利。

Hello,

Thanks for your response. Based on my research, I am able to receive the IE
event on my side. I now share the following information with you:

1. You will need to create a WinForm application instead of Console
application.
2. I reviewed your code, it seems that the delegates are not mapped to
methods. Please refer to the following code snippet:

//--------------code snippet----------------------
public class Form1 : System.Windows.Forms.Form
{
static private SHDocVw.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass();

public Form1()
{
InitializeComponent();

foreach(SHDocVw.InternetExplorer ie in shellWindows)
{
MessageBox.Show("ie.Location:" + ie.LocationURL);
ie.BeforeNavigate2 += new
SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHan dler(this.ie_BeforeNavigat
e2);
}

public void ie_BeforeNavigate2(object pDisp , ref object url, ref
object Flags, ref object TargetFrameName, ref object PostData, ref object
Headers, ref bool Cancel)
{
MessageBox.Show("event received!");
}
//----------------end of----------------------------

Please check it on your side.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于在C#中自动化Internet Explorer的外部实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆