ASSOC – Windows CMD Command

Display or change the association between a file extension and a file Type

A file extension is the last few characters in a FileName after the period.
So a file called JANUARY.HTML has the file extension.HTML

The File extension is used by Windows to determine the type of information stored in the file and therefore which application(s) will be able to display the information in the file. File extensions are not case sensitive and are not limited to 3 characters.

More than one file extension can be associated with the same File Type.
e.g. both the extension.JPG and the extension.JPEG can be associated with the File Type “jpeg file”

At any one time, a given file extension can only be associated with one File Type.
e.g. If you change the extension.JPG so it is associated with the File Type “txt file” then it’s a normal association with “jpeg file” will disappear. Removing the association to “txt file” does not restore the association to “jpeg file”

File Types can be displayed in the Windows Explorer GUI: [View, Options, File Types] however the spelling is usually different to that expected by the ASSOC command e.g. the File Type “txt file” is displayed in the GUI as “Text Document” and “jpeg file” is displayed as “image/jpeg”

The command ASSOC followed by just a file extension will display the current File Type for that extension.

ASSOC without any parameters will display all the current file associations.

ASSOC with “.ext=” will delete the association for that file extension.

Did you leave the Always Use This Program To Open This File option turned on?
To change it back so it prompts you to specify a program each time, just delete the association for that file type
ASSOC .ext=
[where .ext is the file extension].
Now when you double-click on a file of that type, the system will ask you what program you want to use.

An association can be set for files with no file extension using .=

e.g. associate all no-extension files with notepad:
ASSOC .=txtfile

Using the ASSOC command will edit values stored in the registry at HKey_Classes_Root\.<file extension>
Therefore it’s possible to use registry permissions to protect a file extension and prevent any file association changes.


When CMD Command Extensions are enabled (the default)

If the file Association was successfully changed %ERRORLEVEL% = unchanged, typically this will be 0 but if a previous command set an error level, that will be preserved (this is a bug).
If the File Association could not be changed %ERRORLEVEL% = 1

ASSOC is an internal command.
If Command Extensions are disabled, the ASSOC command will not function.


View file associations:

Add file associations:

Delete a file association:

Repair .REG and .EXE file associations:

Digging through CLASSES_ROOT entries often reveals more than one shell for the same application, for example [open] and [play] these can have subtle differences, changing the default action for a file extension can even invoke a different executable.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *