Registry file association and application—the second strategy for using the registry Friends who like to use the Windows right-click shortcut menu may know that when you select a file (or folder or system icon) and right-click, the system will pop up a menu, and you can choose various "functions" (or "operations") on the menu for you to choose. But have you noticed that after you install some application software, your right-click menu is expanded? Taking winzip as an example, after installing winzip, the right-click menu of the file or folder has added function selections "Add to Zip" and "Add to " in the right-click menu of the file or folder. As shown in Figure 1, seeing this change, we can't help but ask, how are these selections added and can you add them yourself. With these questions in mind, let’s look at the file associations of Windows. Picture 1 What is file association? In layman's terms, it is the various functional items displayed on the right-click menu when selecting different types of files. Each function item corresponds to an association. After selecting a certain function (operation), the system will execute the corresponding processing program. As for what files and what operations correspond to what kind of handlers, they are all recorded in the system registry. Therefore, to truly understand file associations, one must study the registry in depth. Once this problem is solved, we can use the registry to create, modify, and delete associations for files as we wish. Since all the associated information is written in the registry, how is it composed in the registry? We might as well open the registry and observe the respective primary keys under the root key HKEY_CLASSES_ROOT. (This may be easier to illustrate this point) Have you seen a lot of points (.) in front of it, and the back seems to be the primary key of the file extension, as shown in Figure 2 Figure 2 Such as .bat, .txt, .lnk, .bmp, etc. We call this type of primary key "extended primary key", and each extension primary key has a default key value. For example: the default value of the primary key .bat is batfile; the default value of the .lnk primary key is lnkfile. With these two examples, have you seen the rules? That is: if the "extension primary key" is named .xxx (xxx is the extension of a certain type of file), then its default key value is xxxfile. Of course, not all default values are like this, and multiple primary keys may correspond to the same default value. For example: primary key.jpeg and primary key.jpg, their default values jpgfile; the default values of .html and html are htmlfile. Why do you want to say so much about the default values of the primary key of the extension? Let me tell you the reason slowly. The function of this default key value is very important. It is a bridge and link to the file association, which connects the file type (identifies the file type with an extension) with the file association. If you don't believe it, you can change the default key value of a "extended primary key" randomly, and you will find that many of the associated items of this type of file disappeared in the right-click menu. Since this important default key value acts as a bridge, how is the relationship between the other end of the bridge - the file defined? Let's continue to look at the registry and let it explain it to us. It is still under the HKEY_CLASSES_ROOT root key. We can see that there is the following primary key under this root key. Such as: batfile, txtfile, lnkfile, etc. (As shown in Figure 3) Figure 3 These primary keys seem to be the default values of what we just called "extended primary key". Yes, the above default value just turns into the primary key name here - this is the bridge. We call this type of primary key "identification primary key". Generally speaking, there are the following important primary keys under the "identification primary key": (as shown in Figure 4) As shown in Figure 4 DefaultIcon primary key, its function is to define the default icon for this class file.
Shell primary key, its function is the center of this article's discussion - the "lifeline" of file associations. Various associations of files are parasitic under this "root", which defines that this class of files is associated with multiple programs. Its default value is also very useful. Do you still remember that double-clicking the file can open the file (for registered files), this kind of opening uses the default opening method set by the system registry, that is, it is controlled by the default key value of the shell primary key. Each primary key below it can be called the "associated primary key" (as shown in Figure 4). The key name of the "associated primary key" is arbitrary (recommended in English), and its default key value is also of interest to us. Because this default key value will be displayed directly in the right-click menu, and there is a command primary key under each "association primary key", this primary key defines "the corresponding executor of the association". As shown in Figure 5, the connection to this file is obvious. Figure 5 Let’s use the .reg file (the script file of the registry) as an example to illustrate its association process. First, the .reg file has a "extended primary key" under the HKEY_CLASSES_ROOT root key. The default value of .reg is regfile, indicating that the primary key associated with the reg type file is regfile. Then look for the "identification primary key" regfile under the root key. There is a DfaultIcon primary key under the regfile primary key, which is used 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\,1 (represents the second icon in it). There is also a primary key shell called "liferoot" below the regfile primary key, and the association of the reg file is recorded in the shell. Next we will establish a relationship for regt. The steps are: under the shell primary key, create a new primary key xxf (named arbitrary), set its default value to "Xu Xifeng's text editor", and then create a new primary key command under the xxf primary key, set its default value to C:\Windows\%1. The meaning of this default value is: use Notepad to open the current reg file. If there is no %1 parameter, only the Notepad program is run without opening the current file. After setting up, you can check the "right-click menu" of the reg file. Is there an additional "Xu Xifeng's Text Editor" option (as shown in Figure 6), it's great! ~
Figure 6 What is mentioned above is only related to ordinary files. However, in Windows, in addition to files, there are also folders and special documents (such as my computer, drive, recycling bin, etc.). So how do you set up the associations? Then please remember that there are the following important system-related primary keys under the HKEY_CLASSES_ROOT root key: *: It works on all files, it is the same as the association method of "identify primary key".
Directory: It works on general folders.
Folder: It works on all folders, including special files, such as control panel, recycling bin, etc.
Drive: acts on drives, such as A drive, B drive, and C drive.
Unknown: It acts on file types that cannot be recognized by the system, that is, file types that are not registered. The most basic file association is about this. Let’s take a look at the application of file association. One of the applications: Make the MS-DOS method everywhere. Friends who often use DOS may be a little bored because every time they enter DOS, they have to choose "Start\Programs\MS-DOS". Using file association, we can add MS-DOS to the "right-click menu" of any file, which saves much trouble. The method is:
Expand the registry to the HKEY_CLASSES_ROOT\*\shell branch. (Add MS-DOS mode in the "right-click menu" of all files) Create a new primary key "MS-DOS", set its default value to "Enter MS-DOS mode", create a new command primary key under the MS-DOS primary key, set its default value to: "C:\Windows\".
The registry is expanded to the HKEY_CLASSES_ROOT\Folder\shell branch, and (add MS-DOS mode in the "right-click menu" of all folders) settings are the same as above. Application 2: Hidden the small arrow in the shortcut icon. If you think the small arrow in the shortcut icon is a bit confusing, then use the association to remove it, expand the registry to the HKEY_CLASSES_ROOT\lnkfile branch, delete the key value Isshortcut under the lnkfile primary key, and then expand the registry to the HKEY_CLASSES_ROOT\piffile branch, delete the key value Isshortcut under the piffile primary key, and then delete the key value Isshortcut under the piffile primary key, and the job is done. Application 3: Use notepad to edit bat files. Sometimes I want to edit a bat file, but habitually double-click it. This double-click does not open it and edit it, but execute it, which is very annoying. Using the file association of the registry, you can change it. Expand the registry to HKEY_CLASSES_ROOT\batfile\shell branch, and change the default value of the shell primary key from open to edit. Application 4: Change the default icon of a certain type of file. Taking the txt file as an example, change the icon of the txt file to the icon of "My Computer". Expand the registry to HKEY_CLASSES_ROOT\txtfile\DefaultIcon branch, and change the default key value of the primary key DefautIcon to: "C:\Windows\,0" . Application 5: Add "open method" to all files. Expand the registry to HKEY_CLASSES_ROOT\*\shell branch, create a new primary key open_as, set its default value to "Select Open Method", create a new primary key command under the Open_As primary key, set its default value to: "C:Windows\ , openAs_RunDll %1" Application 6: Add "Shutdown" to the right-click menu. Expand the registry to the HEKY_CLASSES_ROOT\Directory\shell branch, create a new primary key close, set its default value to "Shut System", and then under the close primary key, create a new primary key command, set its default value to: "C:\Windows\ , exitwindows" The above six applications can generally summarize the basic structure and basic framework of file associations, clarify the structure and framework of file associations, and add the associations yourself to a piece of cake. As long as you are interested, you can add your right-click menu to full. If you want to know more about file associations, please refer to books and materials about the Windows registry, or contact me, my email is @. Before the article ends, I will tell you a little trick: that is, after the registry has been modified, it needs to be restarted in many occasions before it can take effect. Here I will tell you a method that does not require restart but can quickly change the registry: select "Start\Stop System". After the "Stop System" box pops up, press the Ctrl+Alt+Del key combination, and the "End Task" box appears. Select "Explorer" in it, then click "End Task", wait for a while (about 10 seconds), and a "End Task" confirmation box will appear, and click the "End Task" button. (Source: viphot)