Limit for URL length for "rundll32 url.dll,FileProtocolHandler"?

I have a long URL with tons of parameters that I want to open in the default browser from Java on a Windows system using

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url)

For short URLs like "" this works fine. But for long URLs (say, 2000 characters), this simply does absolutely nothing at all: no exception or anything of the sort, it is simply ignored.

Is there a character limit a) for a Runtime.exec command or b) for the rundll32 url.dll command? If so, what is the limit?

Asked by: Daniel604 | Posted: 23-01-2022

Answer 1

You will be running up against this (archived) operating system/browser specific maximum URL length problem:

For "rundll32 url.dll" (i.e. Microsoft IE) you will be limited to 2,083 characters (including http://).

From where I sit you have two alternatives:

  1. Build (or use) a TinyURL-style service that turns your long-urls into short, redirected ones. However even here you are going to run into the same URL length issue, just within the browser itself rather than your Runtime() statement. e.g. The browser window would open, go to the short-URL which would perform the redirect to the long-URL and fail.

  2. Use a POST request and bury some or all of your URL parameters within it. Rather than using a GET call you can supply very long parameters within the body of an HTTP POST request. This would not be as simple as your example code. In fact this maybe quite tricky (or impossible) with the rundll32 url.dll combination (I am not familiar with it)...

Answered by: Kelsey482 | Posted: 24-02-2022

Answer 2

As an aside, I would suggest using the cross platform or Desktop.browse() instead of Windows only rundll32. This will give you an IOException if it can't open the write application.

Answered by: Kelvin693 | Posted: 24-02-2022

Answer 3

You could also try the Runtime.exec(String []) version, which you may have better luck with. Just take all your space seperated arguments and pass them in as seperate strings:

Runtime.getRuntime().exec(new String [] {"rundll32", "url.dll,FileProtocolHandler", "urlarg1", "urlarg2"});

Answered by: John220 | Posted: 24-02-2022

Answer 4

It will also depend on the version of windows, because you may be exceeding the operating system's MAX_PATH length on the command line?

Answered by: Abigail288 | Posted: 24-02-2022

Similar questions

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)