忘记了,喜欢一个人的感觉

Demon's Blog  »  程序设计  »  在InternetExplorer.Application中显示本地图片

« 对VBS效率的再思考——处理二进制数据
WordPress判断用户是否登录 »

在InternetExplorer.Application中显示本地图片

标签: img, InternetExplorer.Application, VBS, VBScript, 图片

标题: 在InternetExplorer.Application中显示本地图片
作者: Demon
链接: http://demon.tw/programming/internetexplorer-application-img-src.html
版权: 本博客的所有文章,都遵守“署名-非商业性使用-相同方式共享 2.5 中国大陆”协议条款。

很久以前的问题了,一直没解决,今天无意中搜到了答案。

在InternetExplorer.Application对象中显示远程服务器上的图片是没有问题的:

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Document.write "<img src='http://demon.tw/demon.gif' />"
IE.Visible = True

然而,在IE默认的设置下,却无法显示本地图片:

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Document.write "<img src='D:/demon.gif' />"
IE.Visible = True

有人说要使用相对路径,有人说路径要用反斜杠

IE.Document.write "<img src='D:\demon.gif' />"

也有人说要加上协议名称

IE.Document.write "<img src='file:///D:/demon.gif' />"

还有人说加上协议名称并使用反斜杠

IE.Document.write "<img src='file:///D:\demon.gif' />"

我都试过了,没用,百思不得其解。

今天却无意中搜索到一段微软网站上的代码,终于豁然开朗:

Option Explicit
Dim objWshShell, objFSO, strVariableName, objExplorer, strScriptFileDirectorySet objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")strVariableName = "WhateverYouWant"
strScriptFileDirectory = objFSO.GetParentFolderName(wscript.ScriptFullName)' Displays the Internet Explorer informational message window.
DisplayIEwindowwscript.Sleep 4000CloseIEwindow
Wscript.Quit' ~$~----------------------------------------~$~
'            FUNCTIONS & SUBROUTINES
' ~$~----------------------------------------~$~
Sub DisplayIEwindow
' Executes an Internet Explorer window.
Dim strIEregistryKey, strCheckAssociationsKey
strIEregistryKey = "NotExist"On Error Resume Next' The following registry entry will enable local files such as .GIFs to be displayed using IE 7.0, but this setting will not take effect if the web browser is already open (there will be no error messages displayed if this is the case).
strIEregistryKey = objWshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about")wscript.echo strIEregistryKeyIf strIEregistryKey = "NotExist" ThenobjWshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about", 2, "REG_DWORD"wscript.echo "escreve"
End If' Attempts to temporarily prevent Internet Explorer checking to see if it is the default browser (storing the existing value to be restored after disaplying the script's IE window).
strCheckAssociationsKey = objWshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations")
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations", "no", "REG_SZ"Set objExplorer = CreateObject ("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Left = 200
objExplorer.Top = 100
objExplorer.Width = 450
objExplorer.Height = 220
objExplorer.Visible = 1
objExplorer.Document.Body.Scroll = "no"
objExplorer.Document.Body.Style.Cursor = "wait"
objExplorer.Document.Title = "Window Title Name Goes Here" & String(50, ".")objExplorer.Document.Body.InnerHTML = "<img src='file:///" & strScriptFileDirectory & "\pro.gif' align='left'> " & "<b><font size='4'><font color='#008000'>" & strVariableName & " . . .</font></b><br>This application is currently being installed, and may take up to 5 minutes to complete.<p align='center'><font size='3'><b>Installation Start Time:</b> " & Time & "</p></p><p align='center'><font size='2'>*closing this window will <u>not</u> abort the installation<font color='#808080'><br> (this window will close automatically after the process completes)</font></font>"' Attempts to make the open IE window active.
WScript.Sleep 1000
objWshShell.AppActivate "Window Title Name Goes Here"
WScript.Sleep 1001' Removes the added registry key setting used with IE 7.0 if it did not already exist.
If strIEregistryKey = "NotExist" ThenobjWshShell.RegDelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\"
End If' Restores the original Check_Associations registry setting from the script's stored value.
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations", strCheckAssociationsKey, "REG_SZ"
End Sub' ~$~----------------------------------------~$~
Sub CloseIEwindow
' Attemps to close the Internet Explorer window if it was opened by this script.
On Error Resume Next
objExplorer.Quit
End Sub

代码里的注释写得很详细,我就不解释了。什么?看不懂英文?那你点参考链接进去看看原文吧,代码以外的部分都是葡萄牙语,作者不用葡萄牙写注释已经很不错了。

图片显示的问题解决后,VBS也可以写出漂亮的WEB界面了。

参考链接:Script InternetExplorer.Application + img scr

相关文章:

  1. 改变IE查看源文件默认程序的方法
  2. 使用正确版本的XMLHTTP
  3. VBS实现“多线程”
  4. VBS中Run和Exec的区别
  5. VBS调用Windows API函数

随机文章:

  1. 利用WMI打造完美“三无”后门-终焉
  2. 用C语言实现PHP的base64_encode函数
  3. VBS实现Unicode(UTF-16)转UTF-8
  4. NETGEAR WNDRMAC路由器刷OpenWrt
  5. Windows 7 快速共享Internet无线网络

这篇文章发布于 2011年02月19日,星期六,00:36

转载于:https://www.cnblogs.com/developer-ios/p/6354554.html

在InternetExplorer.Application中显示本地图片相关推荐

  1. 在html中显示本地图片

    1.html代码 <a id="a-upload"> <input id="imge" type="file" name= ...

  2. Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/18730223),请尊重他人的辛勤劳动成果,谢谢! 写这篇文 ...

  3. html图片红叉,html 中的本地图片显示红叉.路径没问题

    html 中的本地图片显示红叉.路径没问题0 My trip around the usa on a segway Segway'n USA Documenting my trip around th ...

  4. (转)Silverlight显示本地图片、Stream转Byte数组

    转载自:http://www.cnblogs.com/forgetu/archive/2010/08/07/silverlight-load-local-image-stream-to-byte-ar ...

  5. Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果...

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/20481185),请尊重他人的辛勤劳动成果,谢谢! 大家好! ...

  6. java jframe显示图片_java怎么在JFrame中显示动态图片

    java怎么在JFrame中显示动态图片 (2012-09-16 23:39:54) 标签: 杂谈 import java.awt.Graphics; import javax.swing.Image ...

  7. c# picturebox控件显示本地图片和显示网上的图片

    显示本地图片 pictureBox1.Image=Image.FormFile(@"图片路径"); 显示网络图片 pictureBox1.ImageLocation = @&quo ...

  8. 在MarkDown中插入本地图片

    在MarkDown中插入本地图片 用法: ![图片描述](图片网络地址) ![图片描述](本地图片相对路径) 注意: 插入本地图片的时候一定是相对路径 例如: ![项目布局](./Pictures/1 ...

  9. java实现本地图片转urljava中映射本地图片地址为url访问

    1.编写一个工具类PhotoUtils实现WebMvcConfigurer,然后重写addResourceHandlers方法即可 @Component public class PhotoUtils ...

最新文章

  1. 【深度学习】模式识别技术探索之决策树(Decision tree)
  2. 【LeetCode从零单排】No.8 String to Integer (丧心病狂的一道题)
  3. 谷歌io大会 android p,谷歌I/O大会发布全新电视系统 Android P让电视变的更加智能...
  4. 【轻端重云和边缘架构新模式】
  5. python全栈面试题_python面试题大全(一)
  6. 输入3个双精度实数,分别求出它们的和,平均值,平方和以及平方和的开方
  7. Java Web学习总结(9)——servlet和Jsp生命周期解读
  8. mysql 垂直分表技术的实战演练,有实战代码。
  9. 网站开发常用链接信息
  10. java私塾(java私塾初级模拟银源代码)
  11. 【IoT】创业指南:智能硬件产品原型设计指南
  12. 网路岗 - Cisco 交换机端口镜像配置图解
  13. 解决Cipher Suites导致的“未能创建 SSL/TLS 安全通道”异常问题
  14. zcmu-5066: 黑暗长廊
  15. [转]如何修炼成某一领域的高手?
  16. 远程工具MobaXterm安装和使用教程
  17. 座席成功所需的 5 项数字客户服务技能
  18. HBase初识之学生心得总结
  19. 从新手运气看幸存者偏差
  20. 界面自动化脚本开发案例

热门文章

  1. linux logrotate进行日志分割
  2. MVC 3 基本操作增加修改
  3. 队列处理器 WorkQueueT
  4. 猎头职位:存储翘首EMC高薪诚聘高级软件工程师SH
  5. 做更好的“教练”,用对抗训练增强“知识追踪”
  6. 让全球数亿人拍摄到更美的照片,【北京三星研究院】招聘
  7. 刚刚!频域通道注意力网络FcaNet开源了!
  8. TinaFace:人脸检测新纪录!
  9. Github趋势榜第一!英伟达发布StyleGAN2,生成图像逼真到吓人
  10. 谷歌视频架构搜索:从 EvaNet 到 TinyVideoNet