• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15874
  • Last Modified:

How do open a webpage with a BATCH file

Hi,

I have created and batch file and i need to open an address i.e www.internet.com/email.asp?subject=error?body=hello?to=sss@ss.com

and then close the browser again automatically.. basically call a page to send an email from the batch file when an error occurs.
0
zoomzoomdevelopers
Asked:
zoomzoomdevelopers
  • 4
  • 2
  • 2
2 Solutions
 
RanjeetRainCommented:
It is possible to open a web page from a batch file. For example, put the command

START http://www.google.com/

to open google.com. However, it is not possible to close a web page from a batch file, unless and untill the page closes itself.

A better option for you may be to use one of command line email sending utilities. Such utilities either work on a built-in SMTP server or use MAPI (on windows) or sendmail (on UNIX).
0
 
InteractiveMindCommented:
You need to pass the page to your browser, so, if you're using Internet Explorer, then this should do it:

start "c:\program files\internet explorer\iexplore.exe" "www.internet.com/email.asp?subject=error?body=hello?to=sss@ss.com"

Then, to close the application, you need to download a small program, called "PSKILL.exe", which allows you to close processes via DOS (/batch file). This can be downloaded here: http://www.sysinternals.com/files/pskill.zip
You can then use it like so:

pskill iexplore.exe

So, put together, this should do it:

@echo off
title Send Email

:: Start browser:
start "c:\program files\internet explorer\iexplore.exe" "www.internet.com/email.asp?subject=error?body=hello?to=sss@ss.com"

:: Pause for 1 second:
set pause=1
ping -n %pause% localhost>nul

:: Close browser:
pskill "iexplore.exe"

:: Complete!


I hope that helps.

Regards;
0
 
InteractiveMindCommented:
As RanjeetRain said, you can actually just pass the webpage to the start.exe application. So, replace this line:

start "c:\program files\internet explorer\iexplore.exe" "www.internet.com/email.asp?subject=error?body=hello?to=sss@ss.com"

with this:

start "http://www.internet.com/email.asp?subject=error?body=hello?to=sss@ss.com"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zoomzoomdevelopersAuthor Commented:
Interactive mind, what is the reason for the:

:: Pause for 1 second:
set pause=1
ping -n %pause% localhost>nul


?????
0
 
RanjeetRainCommented:
That's a way to give the batch file some time to execute before trying to close Explorer. But you never know whether or not the page has been actually been able to send the email by the time you try to kill it.

Btw, did you check out any of the command line mail send utilities I recommended. That would be a much cleaner approach and failproof as well.
0
 
zoomzoomdevelopersAuthor Commented:
Yes, have checked the programs but due to firewall the mail utilities return a connection error to port 25 which is what we use to send outgoing SMPT mails.

Now developing an ASP page so that to send the mail from but like you said i'll have to work out the pause times to allow it to send correctly before closing.

Sweeter than a sweet thing!

Really appreciate your help ranjeet & Interactive.
0
 
RanjeetRainCommented:
Glad to help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now