CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

Windows – How to modify file associations from command prompt?

Have you ever observed; when we open a file in Windows, it will open in an Application that supports the file? When you open a media file to play the music or a video, it will NOT open in a Notepad, right? How does the Operating System knows, the Application in which the file has to open? The answer is, file associations.

Windows maintains file associations where it maps file extensions with respective file types and these are associated with respective applications in order to open the right application when the user attempts to open the file. For example, if you open Microsoft Excel file, Windows opens it in Microsoft Excel Application. We can control the file associations from Windows command prompt also; we discuss this through this Article.

How to display existing file associations?

Windows provides ASSOC command to display the file associations. When we run the command from Windows command prompt, without passing any parameters; it will display the list of current associations.

C:\>assoc

We can also find out specific file extension association, by simply passing the file extension as an argument to this ASSOC command. Here the command looks like;

C:\>assoc .xls
.xls=Excel.Sheet.8

Observe that, for .xls file extension it is showing the association as “Excel.Sheet.8“. What is this? This is a file type (or an id), stored in the file associations. Using this file type (or an id), Windows retrieves the Application to launch, when the file with .xls extension is open.

If the requested file association is not exists, you will see the below message;

C:\>assoc .xyz
File association not found for extension .xyz

How to create file associations?

File associations can be created by assigning the file type to the file extension. When we pass this information to ASSOC command as an argument, it will create a file association.

If you do not have permission to create the file associations; you will get an Error message. If you want to run the below command from command prompt, you need to open the Windows command prompt with Administrative permissions;

C:\>assoc .abc=exefile
Access is denied.
Error occurred while processing: .abc.

Otherwise, file association will be created and it will be displayed on the screen. Here is an example;

C:\>assoc .abc=exefile
.abc=exefile

How to delete file associations?

To delete the file association, we just need to assign no value to the file extension. For example, below command deletes the file association for .abc extension; which was created in our previous section.

C:\>assoc .abc=

C:\>

Observe that no message was displayed after deleting the file association. Let’s verify whether the file association removed, by using below command; it shows file association not found;

C:\>assoc .abc
File association not found for extension .abc

If you do not have permission to delete the file associations, you will get “Access denied” error message. Run the command with  fro command prompt, with Administrative permissions;

C:\>assoc .abc=
Access is denied.

// Malin

Windows – How to modify file associations from command prompt?

Leave a Reply

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

Scroll to top