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.
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.
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.
This question seems to have a lot of assumptions in it that are questionable.
First, why do you want to use a .reg file to remove the file association? Why not just do it from the user interface? Are you doing this across many workstations?
Second, I fail to see why the .reg file you linked to would only work with previously unassociated file extensions.
Anyway, to delete a key using a .reg file, you prefix a hyphen to the key name. To remove a value, you set it to hyphen-sign. It all spelled out here.
To remove a file association, you need to delete the key for the file extension, e.g.
[-HKEY_CLASSES_ROOT\.dat]
This alone would prevent the file from being opened, but for completeness you should also remove the key for the type name, which was the default value under the file extension key. Example:
[-HKEY_CLASSES_ROOT\dat_auto_file]