反射终端仿真器 - 与 IE 集成
我正在尝试在反射终端模拟器中运行的遗留应用程序和在 IE 中运行的基于浏览器的应用程序之间实现一些集成。
我正在使用主机启动脚本,以便将维护和部署问题隔离到旧应用程序中。 所有脚本都将在旧版应用程序中生成,并使用转义序列传输到 Reflection。
我目前能够:
- 启动 IE
- 设置隐藏工具栏等选项
- 导航到 URL
- 将状态信息传输回旧版应用程序
- 等待旧版应用程序发出“关闭”信号
- 关闭 IE
以下是执行此操作的 VBA 代码
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.ToolBar = false
objIE.Navigate("http://www.google.com/")
objIE.Visible = true
Session.Transmit "OK" & CR
Session.WaitForString "CLOSE", 0, rcAllowKeystrokes
objIE.Quit
End Sub
:是脚本继续运行,直到它从旧应用程序获取关闭命令。
我想要做的是使用一个脚本来启动浏览器,然后使用另一个脚本来关闭它或将其重新用于另一个 URL。 但是,我一直无法找到一种方法来跨脚本调用保存对 IE 的引用。 将 objIE 声明为 Sub Main 之外的 Global 没有帮助。 Session 对象确实在脚本调用中持续存在,但它似乎没有可用于此目的的属性。 (Session 确实有一个 UserData 属性,但那是一个字符串,而不是一个对象。)
这是我想要做的一个示例:
脚本 1 - 打开 IE 和 IE。 保持打开状态:
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.ToolBar = false
objIE.Navigate("http://www.google.com/")
objIE.Visible = true
Session.Transmit "OK" & CR
End Sub
脚本 2 - 将原始 IE 窗口发送到新的 URL
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = FindOriginalIE()
objIE.Navigate("http://www.stackoverflow.com/")
Session.Transmit "OK" & CR
End Sub
脚本 3 - 关闭 IE
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = FindOriginalIE()
objIE.Quit
Session.Transmit "OK" & CR
End Sub
我不明白的部分是如何实现脚本 2 和 3 中使用的 FindOriginalIE() 函数。
我尝试使用 GetObject( ) 而不是 CreateObject(),但这让我无处可去。 GetObject() 不会打开新的 IE 窗口,也不会查找现有的 IE 窗口。 我怀疑这是因为我在 Citrix 下运行,但我不确定。
我现在唯一的线索是尝试使用 IE 的 hWND 重新连接到原始窗口,或者使用 DDE 而不是 OLE。 然而,我在这两个方面都没有太多运气,主要是因为缺乏文档。
所以,我的问题是:
- 我想做的事情是否可能 使用 OLE? 也就是说有没有办法 保持我对 IE 的处理 主机发起脚本调用?
- 我应该期望 GetObject() 起作用吗? 或者这是一个死胡同?
- 是否可以使用Win32 API 在主机启动的脚本中 使用 hWND 重新连接 IE?
非常感谢任何相关文章、示例代码或其他见解的链接。
I'm trying to implement some integration between a legacy app running in the Reflection Terminal Emulator and a browser-based app running in IE.
I'm using Host Initiated Scripts so that maintenance and deployment issues are isolated to the legacy app. All scripts will be generated in the legacy app and transmitted to Reflection using escape sequences.
I am currently able to:
- Launch IE
- Set options such as hiding toolbars
- Navigate to a URL
- Transmit status info back to the legacy app
- Wait for a "close" signal from the legacy app
- Close IE
Here's VBA code to do that:
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.ToolBar = false
objIE.Navigate("http://www.google.com/")
objIE.Visible = true
Session.Transmit "OK" & CR
Session.WaitForString "CLOSE", 0, rcAllowKeystrokes
objIE.Quit
End Sub
The problem with this is that the script continues to run until it gets the close command from the legacy app.
What I want to do is use one script to launch the browser, and another to either close it or re-use it for another URL. However, I haven't been able to find a way to save my reference to IE across script calls. Declaring objIE as Global outside Sub Main didn't help. The Session object does persist across script calls, but it doesn't appear to have a property that I can use for this purpose. (Session does have a UserData property, but that's a String, not an Object.)
Here's an example of what I'd like to do:
Script 1 - Open IE & Leave it Open:
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.ToolBar = false
objIE.Navigate("http://www.google.com/")
objIE.Visible = true
Session.Transmit "OK" & CR
End Sub
Script 2 - Send original IE window to a new URL
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = FindOriginalIE()
objIE.Navigate("http://www.stackoverflow.com/")
Session.Transmit "OK" & CR
End Sub
Script 3 - Close IE
Sub Main
Dim CR as String
CR = CHR$(rcCR)
Dim objIE as Object
Set objIE = FindOriginalIE()
objIE.Quit
Session.Transmit "OK" & CR
End Sub
The part that I can't figure out is how to implement the FindOriginalIE() function used in Scripts 2 and 3.
I tried using GetObject() instead of CreateObject(), but that got me nowhere. GetObject() won't open a new IE window, or find an existing one. I suspect this is because I'm running under Citrix, but I'm not sure.
My only leads right now are to try using IE's hWND to reconnect to the original window, or to use DDE instead of OLE. I haven't had much luck with either of those however, mainly because of a lack of documentation.
So, my questions are:
- Is what I'm trying to do possible
using OLE? That is, is there a way
to persist my handle to IE across
host initiated script calls? - Should I expect GetObject() to work,
or is that a dead end? - Is it possible to use the Win32 API
in a host initiated script to
re-connect to IE using hWND?
Any links to related articles, sample code, or other insights are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK GetObject 只是不支持 InternetExplorer 对象。 然而,这还不是结束:) 许多其他方式你可以将它从 shell32 的 windows 集合中拉出来。 为了使示例代码(改编自上面链接中的代码)正常工作,您需要设置对以下内容的引用:
我认为可能值得讨论一下您想要完成的任务。 机器人化 IE 是一种相当笨拙的方法(我经常对此感到内疚),但可能有一种更好、资源消耗更少的方法。
AFAIK GetObject is just not supported for the InternetExplorer object. However this is not the end:) Among many other ways you can yank it out of the windows collection of shell32. For the example code (adapted from code in the link above) to work you need to set a reference to the following:
I think it might be worth discussing what you are trying to accomplish though. Roboting IE is a pretty kludgey approach (of which I am often guilty), but there might be a better, less resource intensive way.