Batch file to open URL with ampersand in new browser window?

August 8, 2012 at 17:13:31
Specs: Windows Server 2003
I'm trying to make my batch file open specific websites in new browser windows. I'm doing this on a work computer where I cannot change the settings to open new links automatically in new windows (plus some users wouldn't want /everything/ in new windows, anyhow).

The below works when there are no ampersands, of course.

start /max "" "%ProgramFiles(x86)%\Internet Explorer\iexplore.exe"

I know I could put a caret ^ in front of the ampersands to make it work, however some of the codes I have would input a user's password, which could potentially have an ampersand in it. I have Excel creating the batch file and I believe it would take much more code to put carets in front of possible ampersands than it would to figure out how to make the above code work.

The ampersand links work fine when they are in quotation marks, such as when they do not open in new windows, but I can't figure out a way to include the pathing for IE and the URL.

See More: Batch file to open URL with ampersand in new browser window?

Report •

August 8, 2012 at 17:47:56
if it is a fixed set of urls, you could maybe use ip address instead of url containg &.

Report •

August 8, 2012 at 20:22:22
The trouble isn't so much the URLs, it's the fact that the users' passwords could potentially contain ampersands. I don't trust them to follow instructions like: if your password has the & symbol, please type the ^ symbol before it, even though your actual password does not contain the ^ symbol: ^&
The Excel document I have embeds the users' login credentials inside the URLs for immediate access to websites and without the ability to put the entire URL in quotes, users with & signs in their password would have files that don't work. All this because I need the websites to open in a new browser window! *sigh*
Any ideas?

Report •

August 9, 2012 at 09:01:02
Question: Why are you using Excel VBA to make a batch file? It seems easier to me to use Excel VBA to call ShellExecute(). (Note: In that article, the author uses "Public Declare", but it should be "Private Declare". ) As an added bonus, it'll actually work on 32-bit versions, and with the user's default browser settings.

How To Ask Questions The Smart Way

Report •

Related Solutions

August 9, 2012 at 12:44:48
I looked into that link and I'm not sure it would work for what I'm trying to do (but I am new to all of this so please correct me if I'm wrong). The goal is to create a batch file in the Startup folder that will open the user's desired applications/websites that are normally opened each day to automate the process.

Since each user is different, I have the Excel file set up with several drop down boxes where the user selects his or her options and then Excel creates the batch file and puts it in the Startup folder. I have it set up so each website can be opened as another tab in an existing browser or as a completely new browser window. I also have some websites that require a login prompt for the user's credentials so Excel will format the URL with their credentials included.

The problem arises when the websites with logins are chosen to open in a new window. If the user has an ampersand (&) in their password, it won't work. It works when it opens as another tab in an existing window since the URL in that command is enclosed in quotes, but the URL cannot be enclosed in quotes when it opens in a new browser window, hence the problem.

With this in mind, would ShellExecute() still work?

Report •

August 9, 2012 at 13:37:50
Perhaps you could simplify your life, by telling the client that if they use special chars that the automated system will not work, so either they have the convience, or they choose to do it themselves?

:: mike

Report •

Ask Question