You may know that when you select a file, folder, or System icon, right-click the shortcut menu and a menu will pop up, you can choose among the various "functions" or "operations" on the menu, but have you noticed that after you install some application software, your right-click menu is not expanded. Take winzip as an example, after winzip is installed, the options "Add to Zip" and "Add to xxx.zip" and "Add to xxx.zip" are added to the context menu of the file or folder. Once you see this change, you can't help but ask, you can add these options on your own. With these problems, let's look at the file association in Windows.
Screen. width-500) this. width = screen. width-500; "border = 0>
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. Select a function operation), and the system will execute 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 illustrate.) Do you see a lot of vertices above?) The following is the primary key of the file extension, as shown in figure 2.
Screen. width-500) this. width = screen. width-500; "border = 0>
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. The default value is also very useful. Do you still remember to double-click the file to open the file for the registered file), this open is to use 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 any recommended in 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.
Screen. width-500) this. width = screen. width-500; "border = 0>
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 a new primary key xxf name arbitrary), set its default value to "Xu Xifeng's text editor", and then create a primary key command under the xxf primary key, 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 completed, you can check whether the "right-click menu" of the reg file contains "Xu Xifeng's text editor" Option 6)
Screen. width-500) this. width = screen. width-500; "border = 0>
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 right-click menu of all files) create a primary key MS-DOS, set its default value to enter MS-DOS mode, create a command primary key under the primary key of the MS-DOS, set the default value to "C: \ Windows \ command.com ".
In addition, the Registry expands to the HKEY_CLASSES_ROOT \ Folder \ shell branch, and add the MS-DOS Method to the right-click menu in all folders) settings are the same 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 \ explorer.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 \ close 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.