I'm building something similar to the CMD program. I want to add a command to open a webpage.
something like: start_web:google.com. My program needs to recognize the start_web: command and than open google.com or some other webpage. Is there any way how to separate start_web: and google.com?
I don't want my program to scan for every webpage out there...
This is what I got:
@Echo off
Echo.
Set /p command= com>
If command== start_web:(a website) <- This were I'm stuck
start (a website)
Exit
(I'm not a professional programmer, I learned everything on the web)
Open a webpage with a Batch program
Moderator: DosItHelp
Re: Open a webpage with a Batch program
Code: Select all
for /F "tokens=1,2 delims=:" %%G IN ("%command%") DO set website=%%H
Re: Open a webpage with a Batch program
All you need is something like this:
This will start Internet Explorer and open http://www.google.com
Or in a batch (first parameter is a web's URL):
Saso
Code: Select all
"C:\Program Files\Internet Explorer\iexplore.exe" www.google.com
This will start Internet Explorer and open http://www.google.com
Or in a batch (first parameter is a web's URL):
Code: Select all
@echo off
if "%1"=="" goto :EOF
"C:\Program Files\Internet Explorer\iexplore.exe" %1
Code: Select all
c:\OpenURL.cmd www.google.com
Saso
Re: Open a webpage with a Batch program
Thanks Squashman, Your code helped me a lot. This is the result:
Code: Select all
@Echo off
Color 02
:Start
CLS
Set /p command= com:
If %command%== stop Exit
Set Search=start_web:
Set command|findstr /b "command="|findstr /i %Search% >nul
If Errorlevel 1 (goto Fail) Else (goto Web)
:Fail
Echo.
Echo Please try again.
Pause
Goto start
:Web
For /F "tokens=1,2 delims=:" %%G In ("%command%") Do Set website=%%H
Start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" "https://www.%website%"
Goto start
Re: Open a webpage with a Batch program
Here's some code that I distilled from a desktop shortcut created from my browser. These two statements seem to be the minimum to open an URL.
This approach allows the system to open the .URL file extension with the default browser, so in theory, there is no need to specify explorers, chromes or other browsers. I only tested it with Firefox. I hope that this is of use.
John
Code: Select all
echo.[InternetShortcut] >"%temp%\DOSTips.URL"
echo.URL=http://www.dostips.com/ >>"%temp%\DOSTips.URL"
"%temp%\DOSTips.URL"
This approach allows the system to open the .URL file extension with the default browser, so in theory, there is no need to specify explorers, chromes or other browsers. I only tested it with Firefox. I hope that this is of use.
John