How to associate double file extension to application on Windows 10

80 Views Asked by At

I want to associate a file extension .mps.gz to an application on Windows 10.

The .gz extension should not be affected. How can I do this?

1

There are 1 best solutions below

0
Anders On

You cannot in general because Windows only cares about the text after the last period.

There are of course ways to hack around it. The naive way would be for your application to handle it. If the original registration looks like

HKCR\gzfile\shell\=open
                 \open\command=c:\otherapp.exe "%1"

you would change it to

HKCR\gzfile\shell\=myapp
                 \open\command\=c:\otherapp.exe "%1"
                 \myapp\command\=c:\myapp.exe "%1"

And if myapp.exe is executed with something you don't handle you would call ShellExecuteEx on the file and set lpVerb to open.

A better solution would be to decide inside the shell before anything is executed. For Windows 95 to 10 you could implement IContextMenu and only add your default menu item in QueryContextMenu if you like the file in the data object. The MayChangeDefaultMenu subkey must exist for this to work. On Windows 7, 8 and 10 you could implement IExplorerCommandState instead if you prefer a static verb.

For Windows 11 I suppose you are going to handle IExplorerCommand::GetState but I don't know if this lets you become the default handler.