File Type Association of the Registry

Source: Internet
Author: User

Address: http://hi.baidu.com/tanry/blog/item/31c9b93833eb87c1d46225c2.html

What is File Association? In other words, it is the function items displayed on the right-click menu when selecting different types of files. Each function item corresponds to an association. When a function (operation) is selected, the system executes the corresponding processing program. As for what file operations correspond to what kind of handler, it is recorded in the system registry. Therefore, to really find out the file association, you must thoroughly study the registry. After this problem is solved, we can use the registry to create, modify, and delete associations for files as needed.
Since the associated information is written in the registry, how does it constitute it in the registry? Open the registry and observe the primary keys under the root key HKEY_CLASSES_ROOT. (This may be easier to describe) Do you see a lot of vertices (.) above, followed by a primary key of the file extension, as shown in Figure 2

DefaultIcon primary key. Its function is to define the default icon of this type of files.
Shell primary key, which is the "root" of File Association in the center of this article. All the associations of files are parasitic under this "root", which defines the association of such files with multiple programs. Its default value is also very useful. Do you still remember to double-click a file to open the file (for registered files), which is the default open method set by the system registry, it is controlled by the default key value of the shell primary key. Each primary key under it can be called "correlated primary key" (4 ). The key name of the "correlated primary key" is arbitrary (it is recommended to use English), and its default key value is also of interest to us. Because this default key value is directly displayed in the right-click menu, and each "associated primary key" has a command primary key, this primary key defines the corresponding execution program of the association ". As shown in figure 5, the Association to this file has been revealed.

The following uses the. reg file (the script file of the registry) as an example to describe the association process.
First, the. reg file has an "extension primary key" under the HKEY_CLASSES_ROOT Root Key ".. The default value of reg is regfile, indicating that the primary key associated with reg files is regfile. Next, find "identify primary key" regfile under the root key, and there is a DfaultIcon primary key under the regfile primary key to define the default icon of the reg file. The default key is the full path File Name of the icon. For example, C: // windows // regedit.exe,1(the first icon in regedit.exe ). Under the primary key of regfile, there is also a primary key shell called the "root" above. The Association of the reg file is recorded in shell. Next we will create an association for regt. Step: Under the shell primary key, create the primary key xxf (with any name), set its default value to "Xu Xifeng's text editor", and then create a primary key command under the primary key xxf, set the default value to C: // Windows // Notepad.exe % 1. The default value is to use NotePad to open the current reg file. If the "% 1" parameter is not specified, only the Notepad program is run and the current file is not opened. After the settings are complete, check whether the "right-click menu" of the reg file adds the "Xu Xifeng Text Editor" option (6)

The above only applies to the Association of common files. However, in Windows, apart from files, folders and special documents (such as my computer, drive, recycle bin, etc ). So how can we set the association? Remember that there are several important system-associated primary keys under the HKEY_CLASSES_ROOT root key:
*: Act on all files. It is the same as the association method of "identify primary key.
Directory: Act on general folders.
Folder: acts on all folders, including special files, such as control panel and recycle bin.
Drive: acts on the Drive, such as Drive A, Drive B, and Drive C.
Unknow: applies to file types that are not recognized by the system, that is, file types that are not registered.
The most basic file association is mentioned here. Let's take a look at the file association application.
One of the applications: Making MS-DOS everywhere.
Often used DOS friends may be somewhat bored, because every time you enter the DOS mode, you must select "Start // program // MS-DOS mode ". With file associations, we can add the MS-DOS Method to the right-click menu of any file, which saves a lot of trouble:
Expand the registry to the HKEY_CLASSES_ROOT // * // shell branch. (Add MS-DOS mode in the context menu of all files) create a primary key MS-DOS, set its default value to enter MS-DOS mode, and create a command primary key under the primary key of the MS-DOS, set the default value to "C: // Windows // command.com ".
Expand the other registry to the HKEY_CLASSES_ROOT // Folder // shell Branch (add MS-DOS mode in the context menu of all folders) as above.
Application 2: Hide the small arrow in the shortcut icon.
If you think the small arrow in the shortcut icon is a little blind, you can remove it by using association and expand the registry to the HKEY_CLASSES_ROOT // lnkfile branch, delete the Isshortcut key value under the primary key of the lnkfile, expand the registry to the HKEY_CLASSES_ROOT // piffile branch, and delete the Isshortcut key value under the primary key of the piffile.
Application 3: use NotePad to edit the bat file.
Sometimes I want to edit the bat file, and habitually double-click it. This double-click does not open and edit it, But executes it, which is annoying. You can change the file association in the registry. Expand the registry to the HKEY_CLASSES_ROOT // batfile // shell branch, and change the default value of the shell primary key from open to edit.
APP 4: Change the default icon of a type of files.
Take the txt file as an example. Change the icon of the txt file to "my computer. Expand the registry to the HKEY_CLASSES_ROOT // txtfile // DefaultIcon branch, and change the default key value of the primary key DefautIcon to "C: // Windows // assumer.exe, 0.
Application 5: add an "open mode" for all files ".
Expand the registry to the HKEY_CLASSES_ROOT // * // shell branch, create the primary key open_as, set its default value to "select Open Mode", create a primary key command under the primary key Open_As, and set its default value: "C: Windows // rundll32.exe shell32.dll, openAs_RunDll % 1"
APP 6: Add "Shut Down" to the right-click menu.
Expand the registry to the HEKY_CLASSES_ROOT // Directory // shell branch, create a primary key close, set its default value to "close the system", and then create a primary key command under the close primary key, set the default value to "C: // Windows // rundll32.exe user.exe, exitwindows"
In the above six applications, the basic structure and framework of file association can be summarized in general, and the structure and framework of file association can be clarified. Adding association by yourself is just a piece of cake. Before the end of the article, I would like to tell you a little trick: that is, after the Registry has been modified, it needs to be restarted in many cases to take effect. Here I will tell you a way to quickly change the Registry without restarting: Select "start/stop system". After the "close system" box appears, press Ctrl + Alt + Del to display the "End Task" box. Select "Explorer" and click "End Task". Wait for a while (about 10 seconds ), the "End Task" confirmation box appears. Click "End Task.

1. Modify the icon of the common file type
In Windows, each file type has its own icon. You can change an icon of a certain file type to an icon you like as follows:
1) Delete the ShellIconCache file from the Windows directory. This file is a buffer for the icon file. The existence of this file makes it unnecessary for the system to load the icon in the initial position of the file, instead of loading the icon from the Icon cache, this accelerates the display of icons in the desktop and resource manager.
2) In HKEY_CLASSES_ROOT /. ext (ext is the extension of the file to be modified. the program data name related to the ext file (for example. the program data related to the bat file is named "batfile ").
3) Open HKEY_CLASSES_ROOT/batfile/DefaultIcon ("batfile" is the program data name found in the previous step ).
4) change the default data of DefaultIcon to the location of your favorite icon.
2. Modify the icon of the system folder
The icon of the system folder is similar to the icon of the common file type. The steps are as follows:
1) Delete the ShellIconCache file from the Windows directory.
2) locate the location of HKEY_CLASSES_ROOT/CLSID/class/DefaultIcon. The identifier of the system folder where the class you want to modify is located.
3) change the default data of DefaultIcon to the location of your favorite icon.
4) refresh the desktop and resource manager to see the changes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.