Win7/xp Using registry associations to specify suffix names and open programs (both manual "graphics" and "C" programming implementations)

Source: Internet
Author: User

Objective:

This article is an introduction to the fundamentals and manual operations. The program implements this function in http://blog.csdn.net/arvon2012/article/details/7839556, while there is a full code download.

Today in the development process, you need to do the suffix and Program Association, so write down the detailed procedures to share with you. Have any comments welcome message!

Goal: I want to customize a suffix name (. Seve) This time, and develop a program (Opo.exe) that is responsible for opening this suffix file. When I double-click a file with a suffix named my custom, my program runs automatically (Opo.exe).

Summary principle:
For Windows, when you double-click a file, Windows opens the program associated with the current file suffix according to the records in his registry. As by default:. txt is associated with nodepad.exe,.doc that is associated with Word. So to associate, it is to make the registry changes. Modifying the registry can be done either manually or through registry programming.

So how does the registry associate the specified suffix with the specified program?
We use examples to explain, the system here is XP (WIN7 system of the registry and XP at least used here is the same), click Start-Run, input regedit (this command for a long time, but I am more stupid, later only to see that it is the register Edit (registry editing).
After opening you can see a few "keys" that we care about and suffix names related to them under HKEY_CLASSES_ROOT. After the point is opened, click Edit-Find, and then enter. txt in the Find field to automatically jump to the location of the. txt, you can see the following on the right side:

In order, the three values are as follows:
1. (default): In the Association of the most important value, determine the current suffix of the file to whom and how to deal with, what you see here is "txtfile". In fact, the. txt key is just the equivalent of an index, there is no actual processing instructions in the key, and the actual processing is given to another key, the name of the key is here the "(default)" given. (Anxious children's shoes can now be searched in the registry txtfile key)


2Content Type: This specifies what type this file content is, this value can accept a lot of parameters, this list of parameters can be found in MSDN to find content type. The significance of this value is that when the system is going to process the contents of the file, the program associated with the suffix will determine how to open and present the contents of the file according to this value.


3.PerceivedType: This value is also a type of token. What's his use? For example, everyone has a feeling, if the content of this value is video. We open some video players, many players first open it is likely to search the computer hard disk, find the files can be played and show in the "playlist", and this search process is based on this value.

The following jumps to the key responsible for the actual processing and opening of the work, for our example,. txt, this processing key, which has already been said, is txtfile, find the key, and all expand, you can see the following:

PS: In the association suffix name and open program, are two keys work in pairs, such as the. txt and txtfile keys here. Let's say the first one is the suffix key, and the second is the process key. This facilitates the subsequent expression.

In the above figure, you can see the level content of the TXT file's processing key. Check the top txtfile to see what's on the right side of the screen:


1. (default): Here is a description of the file type, everyone right-click on the file icon, select Properties, in the properties of the file type box can see this value.
2.EditFlags: Identify the read/write permissions for this file, such as read-only or read-write ... And so on, this can also be modified in the file attributes.
3.FriendlyTypeName: This value is the friendly name of the application (Halo dish, what is the friendly name?). First of all, here's what the unfriendly name is: The application ID, yes, it's just a bunch of numbers that you can't read, so the value you see here is already very good for the human brain to understand and friendly! )。 This value is actually a description of the processing key corresponding to the application, we open the file attributes to find, can also find the figure of this value. Remember, however, that this value is not a determining function. The decision action is in the subkey.

Now go back to the Txtfile key hierarchy chart:

You can see that there are two direct sub-keys for this processing key: 1. DefaultIcon The default icon for this type of file. 2.Shell, which stores the commands that are executed when the file is actually manipulated.

We look directly at the point:

Shell key:
In this key, you can see three sub-keys: Open,print,printto, which is listed here can execute the command, in fact, and the mouse right click on this file, pop-up menu commands corresponding. We are concerned with the open operation, so here we look at what is stored in the command under the open key:
Default key:%systemroot%\system32\notepad. EXE%1
See the wood there? Here is the real designation of the file by whom to open this suffix. This is NOTEPAD.EXE.
and open key parallel to the captial is a number of operations, everyone interested can open research research.

Implement correlation
Now that we know how the suffixes and programs in the registry are related, we also associate a group.
Suffix: opo
Program: Opo.exe

1. Manual mode
We first create manually, and then the program implementation, the principle is the same, but the program is relatively handsome, of course, but also relatively high-end (in some applications).
Mouse Right click HKEY_CLASSES_ROOT, pop-up menu, choose New--Item

1. Suffix key
Create: Then create a key, we give it a name, here is the suffix name:. Opo.
Write value: Select the key, and then double-click (default) in the right interface, and we enter the name of the processing key in the value: Opofile.
Suffix key complete!


2. Handling Keys
Create: As above, the name is written as the (default) value of the above key Opofile
We just want to associate open apps, other messy things we don't care about first, so here's the following:

Right-click Opofile, create key under Opofile key Shell,shell under Create key open (define Open command), open under Create Subkey command.
Write value: Check command, then double-click on the right side of the default, in the pop-up box after the writer Opo.exe location plus% 1, mine is this:

Test:
Now casually find a small program, the name changed to Opo.exe, and then create a text file, renamed to the suffix Opo file. Then double click on this file, the amount ....
This is called the suffix name and the program association, complete! Hey

Win7/xp Using registry associations to specify suffix names and open programs (both manual "graphics" and "C" programming implementations)

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.