Creating a batch file that opens google chrome and

2019-08-14 17:04发布

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.

2条回答
小情绪 Triste *
2楼-- · 2019-08-14 17:46

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
查看更多
仙女界的扛把子
3楼-- · 2019-08-14 17:47

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.

查看更多
登录 后发表回答