2

I'm trying to write a batch file to open gmail in incognito and enter my credentials automatically when the pc starts up. Based on this post I have the following:

@echo off
cls
start %ProgramFiles(x86)%\Google\Chrome\Application\Chrome.exe --incognito "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier"
exit

However, when I double-click the .bat file, a cmd window appears with an error window in front that says:

Windows cannot find 'C:\Program'. Make sure you typed it correctly, and then try again.

I think cmd is evaluating %ProgramFiles(x86)% without putting quotes around it or something. I'm new to writing bat files, so I'm not sure how to fix this.

Here's some deets about my system:

Windows 10 Pro 
V. 1607 
OS Build 14393.479
64-bit
Surface Book
  • could you explain how your question or the answer involves entering credentials automatically? – barlop Dec 12 '16 at 23:17
  • @barlop I haven't gotten that far yet, just wanted to include it in the off chance someone would include it in their answer. From my research I don't think it's possible, except perhaps by executing a javascript file once the page opens. I'll post in the comments if I figure it out. – Travis Heeter Dec 12 '16 at 23:24
  • i've heard of selenium.. another thing , maybe more appropriate, is an extension called iMacros – barlop Dec 12 '16 at 23:29
  • @barlop I was able to enter credentials with AutoHotKey. However, it was a while ago so I don't know the actual script I used. iirc it wasn't as hard as I thought it was going to be. If I find it, I'll post it. – Travis Heeter Aug 9 '17 at 22:01
5

Even If you are using the Environment var

%ProgramFiles(x86)%

usually expands to

C:\Program Files (x86)

Paths having spaces in them have to be enclosed in quotes

Second is that Start uses the first argument in Quotes as title. See Help Start

This changed batch works as expected:

@echo off
cls
start "" "%ProgramFiles(x86)%\Google\Chrome\Application\Chrome.exe" --incognito "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier"
exit
1

The answer from that post was using the user path rather than Program Files (x86). Therefore it makes the unfortunate assumption that there won't be a space in the path.

%userprofile%\AppData\Local\Google\Chrome\Application\Chrome.exe

Since "Program Files (x86)" has a space, you need to surround the path in quotes.

"%ProgramFiles(x86)%\Google\Chrome\Application\Chrome.exe"

0

Since the expansion of {%Programfiles(x86)%} includes a space, you must have quotation marks around it. As a result, you must double the quotation marks you already have in the command line, resulting in a line looking like this:

start "%ProgramFiles(x86)%\Google\Chrome\Application\Chrome.exe --incognito ""https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier"""

Note that it has been quite a while since I needed to do this, and the correct answer could be this one, where the command and the parameter are separately quoted:

start "%ProgramFiles(x86)%\Google\Chrome\Application\Chrome.exe --incognito" "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier"

One of these will work. I just can't remember which one right now.

  • That won't work. The first argument in quotes becomes the window title ... – DavidPostill Dec 12 '16 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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