MIDRANGE dot COM Mailing List Archive



Hi Frank

I think there is yet a shorter way ..

Just pass the path and file name and windows will open the file using the
default handler by the file type.
If it is a xls/xlsx file lt will use Excel , if it's a text file it will
use Notepad etc.
(See association of file types to handlers by clicking My Computer -> Tools
-> Folder options File Types tab

I guess it implicitly call the FileprotocolHandler mentioned by Scott

chgvar var(&cmd) value('\\Someserver\somepath\test.xls')
monmsg iws4010
strpccmd pccmd(&cmd) pause(*no)


message: 2
date: Wed, 08 Aug 2012 22:50:34 -0400
from: Scott Klement <midrange-l@xxxxxxxxxxxxxxxx>
subject: Re: STRPCCMD and CPD0074

Hi Frank,

First of all: NEVER EVER hard-code a path name to a browser. It's
completely pointless, it's wasting valuable space in your URL, and
completely throws away compatibility with future/past versions of
Windows, throws away the user's choice (a user can choose which browser
they prefer to run), etc.

Windows has the facility to find/launch the proper application for a
given path. (That's what happens when you double-click on a file in "My
Computer" or a similar interface.) Why not just pass the URL to that,
and let Windows deal with it?

chgvar var(&cmd) value('rundll32 url,FileProtocolHandler' *bcat &link)
monmsg iws4010
strpccmd pccmd(&cmd) pause(*no)

That doesn't solve your 123 character problem, of course.. but it
eliminates the nasty hard-coding of iexplore. There's another way to do
it that uses the ShellExecute() function of the operating system:

chgvar var(&cmd) value('rundll32 shell32,ShellExec_RunDLL' *bcat &link)
monmsg iws4010
strpccmd pccmd(&cmd) pause(*no)

However, I think Microsoft might've removed the RunDLL version of
ShellExecute from Windows 7? (I'm not sure I ever tried it, but I want
to say that someone told me that...) so you might want to use
FileProtocolHandler instead. (but test them both!)

In either case, it'll open whatever application Windows has configured
to handle that URL, it might be Internet Exploder (yuck!) or it might be
Firefox, Chrome, Safari, or Opera. Whatever the user has configured.
You can also point it to .DOC, .XLS, .PDF, etc files and it'll open them
with whatever the user has configured (probably Word, Excel, Adobe...
but whatever they configured/installed will be used.)

As for a batch file -- I used to use that technique many years ago, and
it can work okay, but I don't like it. Here are the reasons:

1) It's nearly impossible to escape special characters so they don't get
treated specially.

2) It's impossible to eliminate the ugly black DOS box from popping up.

3) On some emulation programs, the multiple successive STRPCCMDs (which
are required) will occur out of order. (I never understood that.)
Unless you add some delays, which of course, slow your program down.

But, if you really want to try the Batch file technique, here's a link
to an article I wrote about that back in 2005:


Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2015 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact