0

I want a vbs for opening Chrome and load a specific URL, but it doesn't work when the directory contains spaces.

My code, referred shell.run with variable, doesn't work. I'm just getting a error window saying

System cannot find the specific file. Error code : 80070002

Set Ws = CreateObject("WScript.Shell")
chromeLuncher = Ws.CurrentDirectory + "\Chrome\Application\chrome.exe --app=https://www.google.com --start-maximized"
Ws.Run DblQuote(chromeLuncher), 1, True

'****************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'****************************************

How can I fix this?

Update 1:

The folder's structure:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         2018/6/4     10:42                Chrome
-a----         2018/6/4     15:23            190 fso.vbs

The Chrome's structure:

Chrome
 └─Application
    ├─61.0.3163.100
    │  ├─default_apps
    │  ├─Extensions
    │  ├─Installer
    │  ├─Locales
    │  ├─swiftshader
    │  ├─VisualElements
    │  └─WidevineCdm
    ├─Dictionaries
    ├─plugins
    ├─SetupMetrics
    └─chrome.exe

Update 2:

I tried the code How to call Run() with parameters, changed my code to:

Set Ws = CreateObject("WScript.Shell")
chromeLuncher = """Ws.CurrentDirectory"" + ""\Chrome\Application\chrome.exe --app=https://www.google.com --start-maximized"""
Ws.Run chromeLuncher,1,True
Ws = Nothing

but still got the same error:

the error

4
  • 1
    You need to add double quotes around the executable path, not the entire commandline. Jun 4, 2018 at 7:46
  • I tried that way, not work when the path is a variable, works fine when the path is a string.
    – Zhili
    Jun 4, 2018 at 8:40
  • No, you didn't. You tried to put a variable inside a string, which VBScript doesn't support. DblQuote(Ws.CurrentDirectory & "/Chrome/Application/chrome.exe") & " --app=..." Also, please don't edit answers into questions. Jun 4, 2018 at 9:30
  • Aaaa, I misunderstood what you mean, it works. Sorry about the misunderstanding and I will remember don't edit answers into questions. Thank you very much!
    – Zhili
    Jun 5, 2018 at 6:14

1 Answer 1

0

Try this code:

Dim myURL 
Dim objShell
Set Ws = CreateObject("WScript.Shell")

myURL = "https://www.google.com"

set objShell = CreateObject("Shell.Application")
objShell.ShellExecute Ws.CurrentDirectory+"\chrome.exe.lnk", myURL, "", "", 3
set objShell = nothing

You could have debugged your code, and you would have seen that the path you specify for chrome is wrong, that is why you receive the error on line 3.

Documentation for ShellExecute method:

https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

Edit: you can place the shortcut to your chrome.exe install folder in the current folder for the vbs script.

4
  • The code works fine when chrome was installed with recommended steps. In my situation, cannot be sure there has one. So I put a installed Chrome floder in the vbs's path. Please see the update.
    – Zhili
    Jun 4, 2018 at 7:33
  • See the edited code. Jun 4, 2018 at 7:48
  • It works. Thanks!
    – Zhili
    Jun 4, 2018 at 8:37
  • I'm glad I could help! Jun 4, 2018 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.