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

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Zhili
  • 141
  • 11
  • 1
    You need to add double quotes around the executable **path**, not the entire commandline. – Ansgar Wiechers Jun 04 '18 at 07:46
  • I tried that way, not work when the path is a variable, works fine when the path is a string. – Zhili Jun 04 '18 at 08: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. – Ansgar Wiechers Jun 04 '18 at 09: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 05 '18 at 06:14

1 Answers1

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.

Mihai Adrian
  • 645
  • 6
  • 17