Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


October 09, 2006

Using URLs in Batch Files


RSS
View this exclusive article with VIP access -- click here to join |
See More Batch Files Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Batch files provide advantages over using desktop shortcuts or browser favorites to connect to frequently used Web sites. You can launch sites without needing to hunt down the page in your favorites list and even use command-line arguments to retrieve specific content much more quickly. If you put the batch files in a common tools directory on the network, you can access them from any machine, even if you're logged on as another user. However, the command shell's treatment of certain common URL characters, such as the percent sign (%), can make batch files containing URLs fail, even though the commands you use will work fine if you type or paste them at a command prompt. When you understand why this problem occurs, you can work around it, and I'll show you how by using a couple of Google and Microsoft Knowledge Base lookups as examples.

Performing a Google Phrase Search
The situations in which I usually see this problem involve extremely long Internet URLs, frequently for reference pages in online specialty sites; however, the problems are the same as you'd encounter with a simple Google phrase search. For example, if you look up the phrase parent process on Google, the URL at the top of the results page will be http://www.google.com/search?q=%22parent+process%22. The Windows command shell can't understand commands that begin with protocol handlers such as "http://", but if you invoke the URL with cmd.exe's Start command, the URL will automatically be passed to the default Web browser. For example, entering the following text at a command prompt

Start http://www.google.com/
 search?q=%22parent+
 process%22 

opens your Web browser and passes the page request to Google. (Although this command appears on several lines here, you would enter it on one line in the command-shell window. The same holds true for the other multiline commands in this article.) So far, so good. . . .

Reader Comments
I noticed that in IE 6 that if I ran a batch file to open multiple URLs, like this:

start http://www.msnbc.msn.com/
start http://www.cnn.com/

the result was that one IE window was open, displaying the last website (cnn.com in this example). I.e., it was reusing the window, even though the IE Option "Reuse windows for launching shortcuts" is not checked. But what I wanted was to open each URL in the batch file in a separate window.

The solution (thanks to Alex) was to add a small delay between each START command. I used the UnxUtils sleep.exe, and using a 1 second delay caused this to work as desired.

Mark_sa March 13, 2008 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

How can I stop and start services from the command line?

...


Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing