Side note . All of the following considerations apply even if you directly modify file associations in the registry, rather than using the default program APIs.
At the first start, your application should collect the previous owners of all file types for which they exist, through IApplicationAssociationRegistration::QueryCurrentDefault and save them stored in your application.
When uninstalling, your application should use IApplicationAssociationRegistration::SetAppAsDefault to try to restore any file association to which it still belongs to the previous owner. For associations, your application still owns, but does not know the previous owners, go to the HKCR and delete the corresponding extension, protocol or MIME type entry. Do not touch any associations that your application is not the current owner - you will rewrite the user's choice.
Of course, I want the batch backup on first start and cleanup on uninstall to be provided as one call to the API programs API by default, but so far they have not decided to generalize this behavior for all applications, you are on your own.
Please note that cleaning up your application upon uninstallation will be specific to uninstalling the user. Any other users who could use the application and change their default values ββwill not be cleared.
You can automate the cleanup for each user by adding a simple task for each user that performs the above steps in the Task Scheduler. The task is scheduled to be performed once, and then removed from the task scheduler. The only potential problem with this approach is that since you do not know how many users will be there, you will not be able to find out when to remove the DLL for this task from the computer. Again, if you leave this DLL in the ProgramData folder, it does not really matter.
source share