File Associations – ASSOC Command

In this short guide we are going to learn how to view and change File Associations from the windows command line (cmd). Lets get started!

What We'll Learn:

Welcome!
This short guide is all about extension associations and file types.

  • We are going to learn, what file types and extension associations are.
  • How we can view the associations between file types and extensions using the windows command line.
  • And how to change the association of certain file type with an extension from the command line.

Lets get started!

What are File Associations in Windows?​

Windows associates every extension with a certain file type so that it knows the type of data contained within that file, and thus how to execute or open it.
For example, windows by referencing the extension association of a .png file knows that it’s an image and opens it with the appropriate application.

File types are names that windows gives to every file of a certain type, for example text files use the txtfile file type.
One file type can also be associated with many extensions. For example, both .7z and .zip extensions are associated with the 7-Zip file type.
On the other hand, an extension can only be associated with one file type.

View Associations Using The Assoc Command​:

Open your command line and use the assoc command without any parameters to view every extension as well as its file type association.

Assoc
File Associations – What they are & How to Change them (ASSOC Command, CMD)

Every extension and file type in your system will immediately show up.
Note the names of the file types that appear, are a bit different than what they are on the GUI.
That’s because windows displays the file type names that are more easily understood to its users rather than those that it uses internally. For example, what you usually see as “Text Document” appears as “txtfile”.
You can view how the name of a file type is usually displayed us simply by typing its name after the assoc command.

Assoc txtfile
File Associations – What they are & How to Change them (ASSOC Command, CMD)

And as you can see the “txtfile” file type is displayed as “text document”.
Using the assoc command we can view and change the file type association of a specific extension simply by typing the assoc command followed by the name of an extension.

Assoc .txt
File Associations – What they are & How to Change them (ASSOC Command, CMD)

The file type of the .txt extension will immediately show up.

Change Associations Using The Command Line:

By changing the extension association of a file type, we can determine which application should be used to open it.
For example, lets make every file with a .txt extension open with Microsoft Word.
First, we must find out what file type word documents use. To do so let’s view the association of an existing extension that opens Microsoft word, such as .docx.

Assoc .docx
File Associations – What they are & How to Change them (ASSOC Command, CMD)

Let’s verify that this is our file type, by typing its name after the assoc command.

Assoc Word.Document.12
File Associations – What they are & How to Change them (ASSOC Command, CMD)

And as you can see this file type indeed opens Microsoft Word documents. As expected.
Now that we know what file type to use let’s associate it with the .txt extension.
To change the file type of an extension simply type the assoc command followed by your extension and make it equal to the file type of your choice.

Assoc .txt=Word.Document.12
File Associations – What they are & How to Change them (ASSOC Command, CMD)

Windows will now treat .txt files as word documents and open them with Microsoft word.
If you get an “Access is denied error” You need to run the command in a command prompt with administrator privileges.

Note that you cannot assign any association to any file type. That’s because the application of your choice might not know how to handle the data contained within your file.
For example, if you were to make every .rar file open as a text document, your text editor would not have been able to read and understand your file.
That’s why its important that are incredibly careful when changing extension associations, the wrong command can easily make files of a certain extension or file type unopenable.

Finally, you can associate a file type to only extensions that do not have any existing associations. For example, to make windows open every file with an unrecognized extension as a text document type the following:

ASSOC .=txtfile

Any file that has an unrecognized extension will now be opened as a text document.

Assoc Command Examples:​

Display every association between the file types and extensions in your computer.           

Assoc

Display the extension association of the txtfile file type.

Assoc txtfile

Display the file type associated with the .txt extension.

Assoc .txt

Associate every .txt extension with the word document file type. This will make every text file open with Microsoft word.

Assoc .txt=Word.Document.12

Associate every extension that does not have any association with the txtfile file type. This will make every unrecognized extension in your computer open as a text file.

Assoc .=txtfile

Assoc Help Output:​

Displays or modifies file extension associations

ASSOC [.ext[=[fileType]]]

.ext      Specifies the file extension to associate the file type with fileType  Specifies the file type to associate with the file extension
Type ASSOC without parameters to display the current file associations.
If ASSOC is invoked with just a file extension, it displays the current file association for that file extension.
Specify nothing for the file type and the command will delete the association for the file extension.

Summary:

  • File associations are the references between extensions, and file types, and they are used so that windows knows how to interact with files.
  • One file type can be associated with many extensions, but an extension can only be associated with one file type.
  • Use the assoc command to change the extension association of a file type and determine which application should be used to open it.

That's It!

You now know what file extension associations and file types are and how you can use them.

If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.

Windows Command Line

Dont Stop Learning!

Windows Command Line Course

No more searching or memorizing commands! This course has everything you need to start learning about the windows command line along with batch scripting.

Read More:

Comments:

Leave a Reply

Your email address will not be published.

Take Your Skills to the next level!

Become one of our beloved students by enrolling into one of our courses. Get started now!