1
votes

I am trying to write a script using VBS however I am having issues getting the code to work properly. I have to be able to run this script using Google Chrome. I am needing this script to fill in the username and password on a website and "log in." I have inspected the page using the developer tools in Google Chrome and without being to specific this is the element ID for the username text box and the password text box on the page respectively.

<input id="user_name_input" type="text" name="username" size="20" value="">

<input id="password_input" type="password" name="password" size="20" value="">

I have been working on it for a while and I cannot get it to run without bombing out. I have found this script online that will open the page correctly but I can't find anything that will get me past that.

Dim iURL
Dim objShell

iURL = "Website URL"

set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)

I know that the Internet Explorer script to set the ID values is

IE.Document.All.Item("user_name_input").Value = "The@Email" 
IE.Document.All.Item("password_input").Value = "Password" 

but this does not work when I need it to run in Chrome. Please help.

2

2 Answers

0
votes

Google chrome doesn't use vbscript. Only Internet Explorer does, and that is in compatibility modes.

Wrong language for your circumstances. Use JScript.

0
votes

Don't copy this text; it will automatically open the chrome just save with .vbs

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 "https://www.google.co.in/"