Reputation: 15
I hope this is an appropriate use of the valuable resource that is this web-site. I understand using % as batch file escape code but can't seem to work through the many examples like this:
[Use %2* in string variable in Windows batch file
They all seem unclear to me. I am looking for a clear, crisp explanation of when these codes are, and are not needed. Obviously I am an amateur programmer. I think the below provides a good example to work with.
I am trying to launch Google searches like this one, from a Win 7 batch file but can't get the params correct. The idea of course is to have it (or something like it) run for different users for instance from a logon script. Any help is appreciated.
Here is a URL that works:
START "" "https://www.google.com/search?num=30&newwindow=1&safe=off&hl=en&biw=1254&bih=661&tbs=qdr%3Am%2Csbd%3A1&q=wschloss+-schloss+-bucci&oq=wschloss+-schloss+-bucci&gs_l=serp.3...44549.47736.0.48642.7.7.0.0.0.0.72.377.7.7.0....0...1c.1.64.serp..7.0.0.Gdz2I8khqmc"
I am trying to do something like this:
START "" "https://www.google.com/search?num=30&newwindow=1&safe=off&hl=en&biw=1254&bih=661&tbs=qdr%3Am%2Csbd%3A1&q=%%USERNAME%%+-schloss+-bucci&oq=%%USERNAME%%+-schloss+-bucci&gs_l=serp.3...44549.47736.0.48642.7.7.0.0.0.0.72.377.7.7.0....0...1c.1.64.serp..7.0.0.Gdz2I8khqmc"
Where, of course, USERNAME is a Windows environment variable
Upvotes: 0
Views: 247
Reputation: 73616
%variablename%
expands the variable contents so %USERNAME%
should have single %
, conversely you'll have to escape the single %
in the search query by repeating them (%%
):
start "" "https://www.google.com/search?num=30&newwindow=1&safe=off&hl=en&biw=1254&bih=661&tbs=qdr%%3Am%%2Csbd%%3A1&q=%USERNAME%+-schloss+-bucci&oq=%USERNAME%+-schloss+-bucci&gs_l=serp.3...44549.47736.0.48642.7.7.0.0.0.0.72.377.7.7.0....0...1c.1.64.serp..7.0.0.Gdz2I8khqmc"
Upvotes: 1