Ged
Ged

Reputation: 13

Need vbscript to open URL links in webpages in Chrome browser not IE

At my place of work, we use IE11 and Chrome. We have a series of Flash files (created via Xelsius Crystal Dashboard) embedded in to HTM pages that access external XML data sources and we can only get them to work by using an HTA app which overcomes the adobe security restrictions in place.

Some of the other links we have on these web pages point to Google Drive Docs and currently they ALWAYS open in IE when clicked. Trouble is, in my organisation, IE doesn't work well with Google Drive so we would like the links to open in Chrome - which does work with Google Docs

Asking people to change their default browser to Chrome doesn't work as the HTA app always opens in IE, so any subsequent links clicked also open in IE.

I've been told that it is possible to force a link to use Chrome using a vbscript using "Shell" command followed by the "path to Chrome" and the "URL to open".

That vbscript would be called with an onclick() event for any navigation button or link on our htm pages (e.g. a onclick="openURLinChrome('link-to-open')"etc)

I have searched for days looking for a way to create this script to no avail, so I have joined here to seek help. There are a few threads here which I thought might help, but they didn't really apply to my problem.

Can anyone suggest a solution?

Many thanks

Upvotes: 0

Views: 49911

Answers (4)

vbguy
vbguy

Reputation: 1

set objAPP= createobject("shell.application")
objAPP.shellexecute"chrome.exe","www.google.com","","",1

Upvotes: 0

Chris_P
Chris_P

Reputation: 71

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

Upvotes: 5

ATek
ATek

Reputation: 825

Something like this.

Sub openURLinChrome(strLink)
     Set wshShell = CreateObject("WScript.Shell")
     strChromePath = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"
         wshShell.Run strChromePath & " -url " & strLink, 1, false
End Sub

Upvotes: 0

MikeC
MikeC

Reputation: 958

The key is to get the path to Chrome.Exe which can be in one of several locations on the drive. Fortunately, it is stored in the Registry; so one needs to read the registry from VB Script. Then it is just a matter of calling it with the URL. Since the path might have spaces in it, it needs to be enclosed in quotes.

Copy the following into notepad, save as OpenChrome.vbs and double-click it in Windows Explorer.

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_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe\Path", "") 
    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"

Upvotes: 10

Related Questions