需要 vbscript 才能在 Chrome 浏览器而不是 IE 浏览器中打开网页中的网址链接



在我的工作地点,我们使用IE11和Chrome。我们有一系列Flash文件(通过Xelsius Crystal Dashboard创建)嵌入到访问外部XML数据源的HTM页面中,我们只能通过使用HTA应用程序来使它们工作,该应用程序克服了现有的Adobe安全限制。

我们在这些网页上的其他一些链接指向Google云端硬盘文档目前,单击它们时始终在IE中打开。麻烦的是,在我的组织中,IE不能很好地与Google Drive配合使用,因此我们希望在Chrome中打开链接 - 它确实适用于Google Docs

要求用户将默认浏览器更改为 Chrome 不起作用,因为 HTA 应用始终在 IE 中打开,因此单击的任何后续链接也会在 IE 中打开。

有人告诉我,可以使用"Shell"命令强制链接使用vbscript使用Chrome,然后是"Chrome路径"和"要打开的URL"。

该 vbscript 将使用 onclick() 事件来调用我们 htm 页面上的任何导航按钮或链接(例如a onclick="openURLinChrome('link-to-open')"etc)

我已经搜索了几天,寻找创建此脚本的方法无济于事,所以我加入了这里寻求帮助。这里有一些我认为可能会有所帮助的线程,但它们并不真正适用于我的问题。

任何人都可以提出解决方案吗?

非常感谢

关键是获取Chrome.Exe的路径,该路径可以位于驱动器上的几个位置之一。幸运的是,它存储在注册表中;所以需要从VB脚本中读取注册表。然后只需使用 URL 调用它即可。由于路径中可能包含空格,因此需要将其括在引号中。

将以下内容复制到记事本中,另存为 OpenChrome.vbs 并在 Windows 资源管理器中双击它。

function readFromRegistry (strRegistryKey, strDefault)
    Dim WSHShell, value

    On Error Resume Next
    Set WSHShell = CreateObject ("WScript.Shell")
    value = WSHShell.RegRead (strRegistryKey)
    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if
    set WSHShell = nothing
end function
function OpenWithChrome(strURL)
    Dim strChrome
    Dim WShellChrome

    strChrome = readFromRegistry ( "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Pathschrome.exePath", "") 
    if (strChrome = "") then
        strChrome = "chrome.exe"
    else
        strChrome = strChrome & "chrome.exe"
    end if
    Set WShellChrome = CreateObject("WScript.Shell")
    strChrome = """" & strChrome & """" & " " & strURL
    WShellChrome.Run strChrome, 1, false
end function
OpenWithChrome "http://www.microsoft.com"
siteA = "https://google.com"
siteB = "https://bing.com"
siteC = "https://yahoo.com"
Const OneSecond = 1000 
Set browobj = CreateObject("Wscript.Shell")
browobj.Run "chrome -url "&siteA
WScript.Sleep OneSecond*20
browobj.Run "chrome -url "&siteB
WScript.Sleep OneSecond*6
browobj.Run "chrome -url "&siteC
WScript.Sleep OneSecond*6
Set browobj = Nothing

像这样的东西。

Sub openURLinChrome(strLink)
     Set wshShell = CreateObject("WScript.Shell")
     strChromePath = "C:Program Files (x86)GoogleChromeApplicationChrome.exe"
         wshShell.Run strChromePath & " -url " & strLink, 1, false
End Sub
set objAPP= createobject("shell.application")
objAPP.shellexecute"chrome.exe","www.google.com","","",1

最新更新