0
votes

In my software I'm using ShellExecuteEx to open a report that is presented as a local .htm file. At times on some end-user systems there's no default file association for the .htm files.

To set such file association up on a pre-Windows 10 system I'd install the following registry keys to use IE:

Key: HKEY_CURRENT_USER\Software\Classes\htm.file\Shell\open\Command
REG_SZ name: ""
REG_SZ value: "C:\Program Files (x86)\Internet Explorer\iexplore.exe" "%1"

Key: HKEY_CURRENT_USER\Software\Classes\.htm
REG_SZ name: ""
REG_SZ value: htm.file

Key: HKEY_CURRENT_USER\Software\Classes\.htm
REG_SZ name: PerceivedType
REG_SZ value: Document

Then I notify Windows Explorer of the change:

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

It works well, but how do you do the same for Microsoft Edge on Windows 10?

PS.:
I don't want to use IE there because it always shows an extra tab with the nag to switch to Edge, which is very confusing for my end-users.

1
You could instead execute Edge with the html file as parameterbolov
Having your software modify user's associations is very probably a bad idea. Likely your program will do harm in the eye's of some users. I'd be inclined to detect the failure of ShellExecuteEx and then open Edge directly. Of course Edge may not be present.David Heffernan
Windows 10 does not allow applications to arbitrarily change file associations. It has to be done via Settings by the user. If you need evidence, install Google Chrome on a Windows 10 system where it has not been installed before and tell the installer you want to set Chrome as the default browser; in doing so, it opens the appropriate Settings page for you to do so yourself. In addition, I've just been involved in the manual migration of more than 25 systems from Windows 7 to Windows 10 Enterprise, including some fresh installs, with not a single one missing an .htm association.Ken White
@KenWhite: I hope you're right. Because it's very frustrating to deal with missing file associations for the basic extensions like .htm. Although, please note that I'm not talking about changing the default web browser. This is about opening a local file with the local path that has .htm extension. PS. Going back to what you described, I guess that anti-trust lawsuit in the late 90's didn't teach MS anything. hah.c00000fd
Yeah, it's him.David Heffernan

1 Answers

0
votes

On Windows 10, it is done with IApplicationAssociationRegistrationInternal ("2a848e25-d688-4aa3-8e55-0c16cb3a2dfb")

created with SHCreateAssociationRegistration

Set "AppX4hxtad77fbk3jkkeerkrm0ze94wjf3s9" for Microsoft Edge ProgId

(tested on Windows 10 - 1803, 17134.820)