Good morning Stefano. Welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you on this post.
The solution at
http://www.codeproject.com/KB/shell/openwith.aspx is the
same as the command:
Rundll32.exe shell32.dll, OpenAs_RunDLL C:\test.jpg
To retrieve the control of launching the selected application in our own
process after we bring up the "Open With" dialog, there is no direct way. (I
will explain the reason in detail). However, we may have some workarounds
depending on your specific context. Let's first look at the possible
solutions, then I will explain "WHY"s.
---- POSSIBLE SOLUTIONS ----
WORKAROUND 1: Building our own "Open With" dialog.
To be honest, rolling our own OpenAs dialog is something that is hard to
work perfectly. There will be many tests to do to eliminate the bugs. We can
get a list of apps registered to execute a certain file type by groveling
the registry
http://windowsxp.mvps.org/OpenWith.htm or using the API:
SHAssocEnumHandlers
http://msdn.microsoft.com/en-us/library/bb762109(VS.85).aspx (The API is
available to Windows Vista and the above).
WORKAROUND 2: If your request can be adjusted to "how to get the selected
application in the 'Open With' dialog after the file is opened by the
default 'Open With' process", we can consider using the process handle:
http://forums.msdn.microsoft.com/en-US/vbide/thread/b1d31d9c-8b0b-4ffd-9372-74008a0632c6/
(see Martin's reply)
---- CAUSES -----
A. WHY can't I retrieve the control to launch the selected application in
our own process from the shell "Open With" dialog?
1. The OpenAs dialog runs in a separate process (rundll32.exe), so we have
no way of marshalling the process handle back from the OpenAs dialog process
into our process
2. Some types of apps do not support returning the process handle. Apps that
use DDE or drop target invocation does not return a process handle because
their model is typically to have one running process that multiple
ShellExecutes call into.
B. WHY isn't the first workaround very perfect?
Workaround 1 is not perfect because I'm not sure how you would actually
execute the file once the user selects the app. It would only work if the
executing app took a command line argument with the file name, which pretty
much rules out anything that uses DDE or IDropTarget.
Please let me know whether my suggestions are helpful to you. If you have
any other questions or concerns, DON'T hesitate to tell me.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.