Thursday, 10 October 2019

Delete Windows file association using .reg file


Question: Using a .reg file, how do I completely remove a file type association? I tried e.g. deleting HKEY_CLASSES_ROOT\myextension_auto_file but that's apparently not enough.


Background: On Windows Vista, I have a .reg file which successfully associates a file type with another application that always needs some parameters passed (which is why just right-click-associating wasn't enough; see .reg file). However, as the .reg file for some reason only works with previously unassociated file extensions, I'm looking to add some commands to it to first delete a given file type association.



Answer



I see you're writing to HKEY_CLASSES_ROOT with that reg file in the question. This hive is a merged view of HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes.


The reason your file only works for previously unassociated files is that writes to HKEY_CLASSES_ROOT redirect to the appropriate key in HKEY_LOCAL_MACHINE (the hive for system defaults and all-user settings). However, you will run into a problem because file association settings in HKEY_CURRENT_USER (which contains per-user settings) override system defaults.


Furthermore, if the extension is controlled by a "default programs" association, it's file association information is stored in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<.ext>. You can check if your extension has this association by checking for the existence of that key.


You can edit your .reg to work for any file, including previously associated files, by duplicating it for those keys in both HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER. Similarly, you can remove the association by deleting the appropriate keys in both hives (including the FileExts location).


A working .reg file to delete an association for a particular extension looks like this (which deletes .blerg assocations):


Windows Registry Editor Version 5.00

; Created with Default Programs Editor
; http://defaultprogramseditor.com/

; Delete Extension
[-HKEY_LOCAL_MACHINE\Software\Classes\.blerg]
[-HKEY_CURRENT_USER\Software\Classes\.blerg]
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.blerg]

However, if you'd prefer not to have to educate yourself on registry internals and the various arcane aspects of Windows file association, I'd recommend that you'd use Default Programs Editor to make these changes- you can even export an action to a .reg file, which seems to fit your needs perfectly.


Default Programs Editor delete extension and save as .reg file


In your case, it's as simple as clicking File Type Settings, then Delete an extension. Select the extension, and instead of saving to the registry, press the small arrow on the Delete Extension button, and click Save to .reg file.... This will produce a complete and commented .reg file of this action which you can save or distribute to other machines.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...