1
votes

So I'm trying to run a CMD prompt as a VBScript because I can't just drop this CMD Line.

Set cmdl = WScript.CreateObject("WScript.Shell")
cmdl.Run "cmd.exe ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""--app="https://app.powerbi.com/"""--kiosk""--fullscreen""--user-data-dir=c:/monitor1""

My dilemma is that every time I try and run this I get the following error:

Script: Script.vbs
Line: 2
Char: 90
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error

I've tried putting in quotes, taking out quotes, moving spaces, etc. and this dang thing is driving me crazy. Does anyone see where my mistake may lie?

3
Type cmd /? to see where your are going wrong. CMD requires switches for anything other than interactive use. - user6017774
What do you mean you're "trying to run a CMD prompt"? You don't need CMD to start Chrome. - Ansgar Wiechers

3 Answers

1
votes

Your command string is broken. In VBScript a string is defined by putting a character sequence between double quotes:

s = "some string"

If you want to use double quotes within a string you need to escape them by doubling them:

s = "some ""quoted"" string"

Also, you don't need cmd.exe for starting an executable via Run, but you do need whitespace between the parameters to the executable.

Change this:

cmdl.Run "cmd.exe ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""--app="https://app.powerbi.com/"""--kiosk""--fullscreen""--user-data-dir=c:/monitor1""

into this:

cmdl.Run """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" --app=https://app.powerbi.com/ --kiosk --fullscreen --user-data-dir=c:/monitor1"
1
votes

The rule is: Use "" to insert " in VBScript literals.

The first violation in your

"cmd.exe ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe""--app="https://app.powerbi.com/"""--kiosk""--fullscreen""--user-data-dir=c:/monitor1""

is

--app="https

This

"cmd.exe ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" --app=""https://app.powerbi.com/"" --kiosk --fullscreen --user-data-dir=""c:/monitor1"""

may be what you want.

A better (scaling) approach is to use a quote function and an array for the parts/arguments:

Function qq(s)
  qq = """" & s & """"
End Function

s = Join(Array( _
      "cmd.exe" _
    , qq("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") _
    , "--app=" & qq("https://app.powerbi.com/") _
    , "--kiosk" _
    , "--fullscreen" _
    , "--user-data-dir=" & qq("c:/monitor1") _
), " ")
WScript.Echo s

output:

cscript a.vbs
cmd.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app="https://app.powerbi.com/" --kiosk
 --fullscreen --user-data-dir="c:/monitor1"
0
votes

This solution is based from @Ekkehard.Horner

So, i liked his method when using the join function with the array.

And, i tried it on my windows 7 (32 bits) and it works like a charme ;)

Function qq(s)
  qq = chr(34) & s & chr(34)
End Function

s = Join(Array( _
      "cmd /c  start chrome" _
    , "--app=" & qq("https://app.powerbi.com/") _
    , "--kiosk" _
    , "--fullscreen" _
    , "--user-data-dir=" & qq("c:/monitor1") _
), " ")
WScript.Echo s
set ws = CreateObject("wscript.shell")
ws.run s,0,false