2

I am trying to associate a specific filetype (eg .doc) to my application. I am currently using IApplicationActivationManager to do this as IApplicationAssociationRegistration::SetAppAsDefault method no longer works for Win 8 and above and so is editing the registry due to the UserChoice\Hash value.

This association will be triggered when the user clicks on my app's settings then choosing "Set as default". So far, IApplicationActivationManager works for me as it mimics one way on how Windows 10 sets a default file type for an application through "Settings -> System -> Default apps -> Choose default apps by file type" when the user chooses to do so.

Is there is a way to focus on the file type programmatically upon opening "...-> Choose default apps by file type"? Or better yet, launch programmatically "...-> Choose default apps by file type -> Choose an app" dialog for that specific file type?

Screenshot of the 'Choose default apps by file type' Windows Settings pane

Screenshot of the 'Choose default apps by file type' Windows Settings pane

Sample code:

procedure TForm1.Btn2Click(Sender: TObject);
const
  OPENSETTINGS = 'Windows.ImmersiveControlPanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel';
  PAGESETTINGSBYFILETYPE = 'page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView';

var
  pAAR: IApplicationActivationManager;
  pid: PDWORD;
  Res: HRESULT;

begin
  Res := CoCreateInstance(CLSID_ApplicationActivationManager, nil,
    CLSCTX_LOCAL_SERVER, IApplicationActivationManager, pAAR);

  if Succeeded(FRes) 
    pAAR.ActivateApplication(OPENSETTINGS, PAGESETTINGSBYFILETYPE, AO_NONE, pid)
  else
    ShowMessage('Failed!');
end;

For example, can the command

page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView

be extended to scroll to and select a specific file type, something like

page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView&‌​filetype=.doc'

? Or some other solution to accomplish the same thing?

Community
  • 1
  • 1
Adz Baywes
  • 51
  • 4
  • 2
    What are you trying to do? – andlabs May 07 '16 at 14:09
  • I am trying to focus a specific file type programmatically, in this example, it's a .doc upon successful launch of Settings -> Choose Default Apps By File Type – Adz Baywes May 08 '16 at 01:44
  • What are you trying to do overall? Create a file association? There's an officially documented way to do that; [check MSDN, under this section](https://msdn.microsoft.com/en-us/library/windows/desktop/ff521657(v=vs.85).aspx). Don't try to imitate a user; that won't work and isn't supported. Or are you trying to force yourself as the default despite the user's wishes? – andlabs May 08 '16 at 02:02
  • No, I am not trying to create a new file association. I am trying to associate my project to be set as default for that particular filetype when the user clicks on "Set this app as default" on my projects settings box. It will still be the user's choice. I just thought of minimizing the clicks the user will have to undergo to accomplish this. – Adz Baywes May 08 '16 at 02:21
  • Ah. That's fine, but what you are attempting is still not the right way to do it, as it's prone to changes in future versions of Windows. Does MSDN not help here? – andlabs May 08 '16 at 02:25
  • Just thinking if there is still a command that can be added to this: 'page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView' to focus on the file extension, and not have the user scroll down on the list of file types. ex: 'page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView&filetype=.doc' – Adz Baywes May 08 '16 at 02:26
  • MSDN does help, some have already been implemented (Open with...). I am adding this method as per the project owner's wishes. If this is how far this method goes, then that's that :) – Adz Baywes May 08 '16 at 02:31

0 Answers0