Elijah W. Gagne
Elijah W. Gagne

Reputation: 2841

Bat file to open webpage with parameters to local file

Creating a bat file with:

start http://www.google.com/search?q=test

Does just what I would want it to do, it opens my default web browser (Chrome in my case) and browses to the URL http://www.google.com/search?q=test.

However, a bat file with:

start file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1

Only opens my default browser and browses to file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html

Note the lack of ?wbt=1. In order to fix this I've tried:

  1. URL encoding the question mark
  2. Running the start command parameters "window name" "file path in quotes"
  3. Putting the file path in variable and passing the variable to start

But none of those work. How can I get this to work?

Upvotes: 3

Views: 6155

Answers (2)

Elijah W. Gagne
Elijah W. Gagne

Reputation: 2841

The best solution I've come up with so far is:

powershell -noprofile -command "[void][System.Diagnostics.Process]::Start('chrome', 'file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1')"

This solution has the batch file launch PowerShell and then use the .NET System.Diagnostics.Process.Start method to launch Chrome with the correct parameter. The only downside is that it makes a browser choice for me and I'd prefer it to use my default browser, but I can live with that. I'll accept another answer (that is not much more complex) that uses the default browser.

Upvotes: 3

Endoro
Endoro

Reputation: 37569

I tested this and got the same result. I'm not really sure, but I guess this belongs to the question mark. The local file system of Windows can never have file names with ?, because this is a "wildcard" like *. I think it is possible that the file name is truncated there.

The following codes also doesn't work or produces only error messages:

start "file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"
start file:///"C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"

Upvotes: 3

Related Questions