ASSOC

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

Syntax

   Read file associations:
   ASSOC
   ASSOC .ext

   Set a file association:
   ASSOC .ext = [fileType]

   Remove a file association:
   ASSOC .ext =

Key
    .ext      : The file extension
    fileType  : The type of file 

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 "jpegfile"

At any one time a given file extension can only be associated with one File Type.

So the path is: File Extension >> File Type >> executable program
e.g. .TXT > txtfile >> \system32\NOTEPAD.EXE

Here is a list of Common File Extensions and FileTypes.

If you change the extension .JPG so it is associated with the File Type "txtfile" then it's normal association with "jpegfile" will disappear. Removing the association to "txtfile" does not restore the association to "jpegfile", but if you restore the association to "jpegfile" with ASSOC that will automatically restore the link for .JPG files back to the original executable program.

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

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

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

Tamper protection

Per user file associations are stored in the registry under HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
Starting with Windows 8, Microsoft introduced “tamper protection” into the registry to prevent any unauthorized changes to file associations (changes not made via the Windows API).

In most cases use of the ASSOC command will result in, the first time opening a file with that extension will prompt the user:
How do you want to open this file? / Keep using this app or An app default was reset

One way to work with these new restrictions is to create the desired file associations manually, and then export that file via a DISM command:
Dism /Online /Export-DefaultAppAssociations:C:\demo\AppAssoc.xml

The exported file can then be specified in group policy, and applied to client machines where it will supersede any choice the user may have manually set.

GUI

File Types can be displayed in Windows Settings under:
Apps ➞ Default apps ➞ Choose default apps by file type

The Settings pane will only display installed applications (FileTypes) and/or an option to install apps from the Windows store. There is no option to manually add a non-Windows store application using the GUI, but you can do this with FTYPE on the command line.

Errorlevels

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 errorlevel, 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.

Examples

View the current file association for .csv files:

C:\> ASSOC .csv
.csv=Excel.csv

Opening .csv files directly in Excel may be harmful, better to select Data > From text file and run the import wizard.
So instead we can associate .csv files with txtfile (the default text editor, typically notepad):

C:\> ASSOC .csv=txtfile

List all the current file associationa and back them up to a text file:

C:\> ASSOC >backup.txt

Delete a file association:

C:\> ASSOC .html=

Repair .REG and .EXE file associations:

C:\> ASSOC .EXE=exefile
C:\> ASSOC .REG=regfile

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.

“Of all forms of caution, caution in love is perhaps the most fatal to true happiness” ~ Bertrand Russell

Related commands

FTYPE - Edit file types (used in file extension associations).
Batch file to list the application associated with a file extension.
Equivalent bash command (Linux): file - Determine file type.
SetUserFTA - Utility to set the file type association.
Raymond Chen - Why do my PDF file associations get reset every time I restart?
Editing Shell entries & Context Menu handlers - Edit the context menu.
Q162059 - Associate Internet Explorer with MS Office files.


 
Copyright © 1999-2024 SS64.com
Some rights reserved