C # Launch default browser with default search query

I need to do a default browser launch with standard search. The default search is what happens when you enter search terms in the URL navigation text box. For example, in Chrome and Firefox, entering puppies in the nav text box by default will lead you to Google results for puppies. In IE, it will do the same, only on Bing.

You can usually invoke the default browser by simply doing something like:

Process.Start("http://google.com"); 

But I cannot assume that the default search provider is Google.

Is there a way to trigger this behavior through C #? The only thing I can do is try to determine which browser is the default, and then execute it directly with the search terms.

Does anyone know any other (preferably a simpler) way?

Update: Just found the code to find the default browser here .

+4
source share
2 answers

If you already know how to find the default browser, I would try using Process.Start("browser\path.exe", "\"? searchterm\"");

This is similar to IE and Chrome.

+2
source

I just tested IE by typing this at the Start → Run prompt:

"c: \ Program Files \ Internet Explorer \ iexplore.exe" "stack overflow"

He started Internet Explorer and was looking for a stack overflow with my default search provider. Since your search terms are not a standard URL, starting with http:// , there is no way for Process.Start to find out how to launch the browser if you have not provided a specific executable file that you want to run.

You can determine the default browser by checking HKEY_CLASSES_ROOT\http\shell\open\command . You can then launch this browser with search terms as a query parameter, and then use this default search provider in browsers.

+1
source

Source: https://habr.com/ru/post/1481215/


All Articles