Open a webpage with a Batch program

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
THR
Posts: 2
Joined: 29 Apr 2015 12:11

Open a webpage with a Batch program

#1 Post by THR » 29 Apr 2015 12:38

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)

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Open a webpage with a Batch program

#2 Post by Squashman » 29 Apr 2015 13:00

Code: Select all

for /F "tokens=1,2 delims=:" %%G IN ("%command%") DO set website=%%H

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Open a webpage with a Batch program

#3 Post by miskox » 30 Apr 2015 04:28

All you need is something like this:

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

THR
Posts: 2
Joined: 29 Apr 2015 12:11

Re: Open a webpage with a Batch program

#4 Post by THR » 30 Apr 2015 06:37

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

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Open a webpage with a Batch program

#5 Post by thefeduke » 13 May 2015 00:08

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.

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

Post Reply