Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

java - Launch associated program or show "Open with" dialog from another program

Under Window Seven, the following command displays a dialog box then terminates without any other action, why?

The expected effect is launching the associated program Notepad++ or at least Notepad

RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL D:docoto.txt

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firstly, note that OpenAs_RunDLL is an undocumented entry point so the only reason to expect it to work is that it appears in the HKEY_CLASSES_ROOT registry as an implementation for the Open With shell verb (in at least some versions of Windows).

This only means it can be expected to work when called by the appropriate shell functions. It does not mean it will necessarily work in any arbitrary context.

On my home machine (Windows Vista) calling OpenAs_RunDLL via rundll32 works (i.e., the specified file is opened using the selected application) when the command is issued via the Start Menu's Run dialog, which can be opened with the keyboard shortcut Windows+R.

It does not work when issued from a command line console window, and the symptoms are the same as you describe: the dialog is presented, but the application is not launched. This is perfectly legitimate behaviour, because you're using an undocumented entry point in a context it wasn't designed for.

Since there is no guarantee that OpenAs_RunDLL will exist at all in future versions of Windows, the upshot is simple: don't use it. Use the supported SHOpenWithDialog API function instead, or use ShellExecute or ShellExecuteEx with the openas verb; the latter may be particularly useful because it is easy to do from a scripting language such as VBScript.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...