how to open "how do you want to open this file" dialog no matter if a standard application suitable for a file type?

user2330fd212 41 Reputation points
2022-03-09T14:56:03.267+00:00

I want to open the following dialog with or without a standard application suitable for a file type.

181514-open.png

I can use ShellExecute to open this dialog. But if there is an default application for that file, for example .txt file.
It will open by notepad directly instead of open the "how do you want to open this file" dialog

(I am using visual studio c++)

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,760 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 85,881 Reputation points
    2022-03-09T15:18:40.117+00:00

1 additional answer

Sort by: Most helpful
  1. Rodney McManamy 1 Reputation point
    2022-04-08T17:39:11.81+00:00

    If you are trying to open the default program FROM a 32 bit program in 64 bit Windows the ShellExecute and ShellExecuteEX may display the "How do you want to open this file?" dialog box each time. This is due to the way that the default program registered itself in Windows I think.

    I was able to reproduce this error on Windows 11 64 bit fresh install where the Photos is set to the Default Program for .jpg files.

    In my case I found that if I use the ShellExecuteExW function and pass the extension in to the .lpClass of SHELLEXECUTEINFOW Type that it works.
    It should also work with the ShellExecuteExA function
    1.) Make sure it's not an exe, reg, or bat file or a url you are trying to open. It has to be a document type of file.
    2.) Use the .lpClass to pass the extension like .lpClass = ".jpg"
    3.) Add the SEE_MASK_CLASSNAME As Long = &H1 to the .fMask parameter you are passing in like .fMask = YourMaskValue Or SEE_MASK_CLASSNAME

    The reason I think this works is it bypasses any redirection and reads directly from the HKEY_CLASSES_ROOT.jpg

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.