0

I'm trying to open the Chrome browser using a .vbs file (below); it didn't work, I'm getting getting error A0401: expected end of statement

I need to trigger the Chrome browser with --diable -web -security using VB Script.

Dim StrURL
Dim ObjhShell
StrURL="http://localhost:7171/"
Set ObjShell = CreateObject("Wscript.Shell")
'ObjShell.Run ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security"
ObjShell.Run "chrome.exe --user-data-dir="C://Chrome dev session" --disable-web-security"
Venkat
  • 27
  • 1
  • 7
  • @mathieu-guindon A better dup would have been a VBScript one, it’s hard enough explaining the differences between VBS and VBA without flagging obvious VBS code question with a VBA one. – user692942 Apr 26 '18 at 17:34
  • 1
    @Lankymart except, there's no difference in escaping quotes in string literals between VBA, VBS, or VB6, so either works, no? – Mathieu Guindon Apr 26 '18 at 17:40
  • @MathieuGuindon Agreed, but that doesn’t help distinguish them when there is a difference, does it?! – user692942 Apr 26 '18 at 17:41
  • And this code that's written will work in VBA, so it's not "Obviously VBS" There is literally 0 difference in this context of this question between VBA and VBS – JNevill Apr 26 '18 at 17:41
  • 1
    @Venkat. Instead use: `ObjShell.Run "chrome.exe --user-data-dir=""C://Chrome dev session"" --disable-web-security"` Notice the double double quotes. See the duplicate for more info (and upvote the answer) – JNevill Apr 26 '18 at 17:43
  • @JNevill It’s using the `WScript` object *(emphasis on the “Script”)*, VBA has it’s own built in methods for executing shell commands. – user692942 Apr 26 '18 at 17:44
  • @Lankymart It's using `Wscript.Shell` Not FSO. Are we talking about the same question here? Furthermore, I use FSO all the time in VBA. – JNevill Apr 26 '18 at 17:45
  • @JNevill You declare a lot of typeless variables in VBA do you? – user692942 Apr 26 '18 at 17:46
  • Nice try. Not biting. Have a good day. – JNevill Apr 26 '18 at 17:47
  • @Lankymart yet the question boils down to getting `foo = "abc"def"xyz"` to compile. VBS vs VBA is irrelevant. – Mathieu Guindon Apr 26 '18 at 17:49
  • @JNevill It’s just a poor argument, you might use COM in VBA all the time doesn’t mean you should. The fact is VBA can access the power of the Windows API but VBS doesn’t have that luxury, COM is the only choice. But just saying it works in both doesn’t help those unfamiliar with the differences, if anything it muddies the waters further. – user692942 Apr 26 '18 at 17:50
  • @MathieuGuindon all’s I was saying is a VBScript dup would have been a better choice. The OP even says they are using [*”vb scripting”*](https://stackoverflow.com/revisions/50047272/1). – user692942 Apr 26 '18 at 17:53
  • Possible duplicate of [About using Double quotes in Vbscript](https://stackoverflow.com/q/15770599/692942). – user692942 Apr 26 '18 at 18:00
  • Possible duplicate of [Adding quotes to a string in VBScript](https://stackoverflow.com/q/2942554/692942). – user692942 Apr 26 '18 at 18:06
  • @JNevill thanks a ton, I was able to open the browser as per your suggestion.. I am trying to append the URL to the browser, which is not happening, request your suggestion. StrURL="http://localhost:7171/" ObjShell.Run "chrome.exe --user-data-dir=""C://Chrome dev session"" --disable-web-security" & StrURL – Venkat Apr 26 '18 at 18:35
  • @JNevill here you go, you've got a fan now...enjoy. You going to tell them they need a space in `StrURL` or should I? – user692942 Apr 26 '18 at 18:48
  • @Lankymart you may not be aware that any help here is much appreciated as long as it satisfies the requirement, may be you could also help?? would surely clap for your help – Venkat Apr 26 '18 at 19:28
  • @Venkat I [did](https://stackoverflow.com/questions/50047272/opening-chrome-browser-with-disabled-websecurity#comment87116217_50047272), but I guess you missed it. – user692942 Apr 26 '18 at 19:30
  • @Lankymart you mean space in StrURL? can you please explain it? right now my need to open the chrome browser and put the URL into it. I tried this as well `ObjShell.Run "chrome.exe --user-data-dir=""C://Chrome dev session"" --disable-web-security" & "http://localhost:7171/" – Venkat Apr 26 '18 at 19:39
  • 1
    @Venkat so `chrome.exe --user-data-dir="C://Chrome dev session" --disable-web-securitylocalhost:7171/` seems right to you? Because that's what you are generating without the space in the string between `--disable-web-security` and the URL. – user692942 Apr 26 '18 at 19:54
  • @Lankymart ,Thanks a ton! if I place the entire string in run window(Win button +R), it just opens chrome browser (security diabled) but it DOESN"T place the URL "localhost:7171/" to it. – Venkat Apr 27 '18 at 16:41
  • Any other solution also welcome.. Pls – Venkat Apr 28 '18 at 04:41

0 Answers0