Assoc - DOS/Command Prompt Reference
[Windows 2000/XP or later] Displays and configures the file associations for the entire system.
* Changing the settings may require administrator privileges or equivalent permissions since it involves modifying system-wide configurations.
* Since it does not alter user-specific settings, changes made with Assoc may not appear to take effect on the surface.
Syntax
-- Display associations assoc [.ext] -- Configure associations assoc .ext=[progid]
Options
.ext |
Specifies file extensions starting with a dot (‘ If you execute ‘assoc’ without specifying a file extension, it will output all currently set associations. |
.ext=progid |
Adding ‘=’ to a file extension performs association configuration. When executed with a specified ProgID in the ‘progid’ position, it sets the extension's association to the specified ProgID. If ‘=’ is specified without a ProgID (omitted), it removes the file's association configuration. |
Details
Assoc manages file associations on a system-wide basis. It operates by correlating file extensions and ProgIDs to handle associations.
File associations have settings for the current user and system-wide settings. Applications like Explorer may use a combination of both settings. However, Assoc operates only on the system-wide settings (it seems to interact with data under HKEY_LOCAL_MACHINE\Software\Classes). Since user-specific settings take precedence, changes made with Assoc may not appear to take effect in some cases.
Note that you can register ProgIDs using the Ftype command.
[Windows Vista? or later] Assoc does not touch ‘Set Default Programs’. Please note that using Assoc does not allow you to change the default program for a file type.
Samples
Sample 1
assoc | findstr /R =txtfile$
Displays a list of extensions using the ProgID ‘txtfile’ for association. Since the list shown by executing ‘assoc’ alone is always in the format ‘.ext=progid
’, you can use Findstr with the /R option to extract almost exact matches of associations by using ‘=progid$’.
Sample 2
for /F "tokens=2 delims==" %A in ('assoc .txt') do assoc ".hoge=%A"
[Extensions] It sets the association for ‘.hoge’ files the same as that for ‘.txt’ files. By using the extended syntax of the For command, this code analyzes the output of Assoc, extracts the ProgID part, and then uses it again as an argument for Assoc.