0

Is it correct to assume that executable files do not show an "Open-With" submenu in the Windows right-click File Explorer context menu?

Is there a Winapi function to detect whether a file is an EXECUTABLE FILE?

(I need to detect this to get the information on whether a file can show an "Open-With" submenu in the Windows right-click File Explorer context menu).

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • 2
    The only safe way to determine what happens in the context menu is to ask the Shell to build it (and possibly scan its items instead of showing it), using something like the code in my comments in that question : https://stackoverflow.com/questions/74084299/how-do-i-retrieve-iterate-win11-iexplorercommand-context-menu-items#comment130827819_74084299 https://pastebin.com/raw/WFqdMyPF – Simon Mourier Nov 25 '22 at 16:20
  • Are you asking about open with or in general, please clarify... – Anders Nov 25 '22 at 17:34
  • As I wrote: I need to detect this to get the information on whether a file can show an **"Open-With"** submenu in the Windows right-click File Explorer context menu. – user1580348 Nov 25 '22 at 19:48
  • Sounds like an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. Why do you need to know this? What is the end goal? – Remy Lebeau Nov 25 '22 at 23:58
  • @RemyLebeau For several reasons: 1. For security reasons: I want to avoid a user of my app could use it to attach an executable disguised as another file type to a PDF document (a behavior which is sometimes used by hackers). 2. I need to open a file using the Open-With menu programmatically. For that, I need to know in advance (before doing other file operations) whether an Open-With menu for that file is available at all. – user1580348 Nov 28 '22 at 16:41

1 Answers1

1

The fact that executable files do not show an "Open-With" submenu does not mean that files do not show an "Open-With" submenu are executable files.

If you want to detect whether a file is an EXECUTABLE FILE. I suggest you could try to use GetBinaryTypeA function

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • Thanks for the hint. Here is the result: https://app.screencast.com/iA7UmOFG4QvUa It shows that exe files are executables but DLL files are not. Is that correct? – user1580348 Nov 28 '22 at 13:21
  • 1
    @user1580348 yes, because DLLs are not **self**-executable by themselves, they can only be loaded and used by executables and other DLLs. – Remy Lebeau Nov 28 '22 at 17:59