So I am just playing with batch files and was curious if it was possible to create a batch file that opens the google browser and without typing into the search box, a variable from my batch file gets put into the search box. Anyone know if that's possible? Thanks.
@echo off
cd c:\program files (x86)\google\application
start chrome.exe www.youtube.com
I can open the web browser, I can even change the code to store the variable, but need to know how to send that variable to the search engine. Youtube i just the website i left it at.
If you use google as search engine, try to pass the keyword like this :
@echo off
start "" chrome.exe www.google.com#q=batch
and if you want add more than a keyword just add the sign +
@echo off
start "" chrome.exe www.google.com#q=batch+vbscript+HTA
You could send raw HTTP request as follows:
start "" "c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://www.youtube.com/results?search_query=simon's cat"
Below is possible approach how-to make it more readable in a batch script (non-systematic approach, as e.g. site
variable joins together protocol and host name). Use appropriate value of engine
variable for a particular host (as it could vary for different servers):
@ECHO OFF >NUL
SETLOCAL EnableExtensions EnableDelayedExpansion
set "chromepath=c:\Program Files (x86)\Google\Chrome\Application" path to chrome
set "site=https://www.youtube.com"
set "engine=results?search_query"
set "search=simon's cat" string to search
start "" "!chromepath!\chrome.exe" "!site!/!engine!=!search!"
Delayed expansion used as any variable in above code could contain cmd
poisonous characters.