• 在InternetExplorer.Application中显示本地图片


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

    在InternetExplorer.Application中显示本地图片

    标签: 

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

    在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, strScriptFileDirectory
    
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    strVariableName = "WhateverYouWant"
    strScriptFileDirectory = objFSO.GetParentFolderName(wscript.ScriptFullName)
    
    ' Displays the Internet Explorer informational message window.
    DisplayIEwindow
    
    wscript.Sleep 4000
    
    CloseIEwindow
    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("HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslankabout")
    
    wscript.echo strIEregistryKey
    
    If strIEregistryKey = "NotExist" Then
        objWshShell.RegWrite "HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslankabout", 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("HKCUSoftwareMicrosoftInternet ExplorerMainCheck_Associations")
    objWshShell.RegWrite "HKCUSoftwareMicrosoftInternet ExplorerMainCheck_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" Then
        objWshShell.RegDelete "HKCUSoftwareMicrosoftWindowsCurrentVersionInternet SettingsoneMapDomainslank"
    End If
    
    ' Restores the original Check_Associations registry setting from the script's stored value.
    objWshShell.RegWrite "HKCUSoftwareMicrosoftInternet ExplorerMainCheck_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. 利用WMI打造完美“三无”后门-终焉
    2. 用C语言实现PHP的base64_encode函数
    3. VBS实现Unicode(UTF-16)转UTF-8
    4. NETGEAR WNDRMAC路由器刷OpenWrt
    5. Windows 7 快速共享Internet无线网络
  • 相关阅读:
    phpredis
    nginx rewrite
    注册公司流程
    WebsitePanel 2.1.0beta配置部分
    Windows下cwRsync搭建步骤
    Windows 2008下部署Exchange Server 2007
    【网站国际化必备】Asp.Net MVC 集成Paypal(贝宝)快速结账 支付接口 ,附源码demo
    Win2008远程多用户登陆的配置方法 另附详细设置: Windows server 2008 R2实现多用户远程连接
    IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称
    利用UDP19端口实施DOS攻击的真实案例
  • 原文地址:https://www.cnblogs.com/developer-ios/p/6354554.html
Copyright © 2020-2023  润新知