Use the Registry File (REG) to add, modify, or delete Windows registry keys and values

Source: Internet
Author: User

1. Introduction

Most of us usually use the Regedit Registry Editor to modify the registry, but this manual operation is time-consuming and laborious. When you want to modify the Registry uniformly for multiple PCs, You have to complain. In some cases, if the Registry Editor is disabled, this method will also become invalid. Therefore, we recommend that you use the reg file to quickly modify the registry.

The reg file is actually a registry script file. The Regedit Registry Editor can use the reg file to import and export the subkeys and values of the Registry. Double-hit regfile (use regedit.exe Registry EditorProgramRun the file) to import the data to the Registry. You can use the reg file to directly modify the Registry without the restrictions of the Registry Editor being disabled. You can use the Regedit Registry Editor to export the specified items in the registry to the reg file for backup. You can send Reg files to multiple PCs for batch registry modification.

Reg files can be modified using any text file editing tool (such as NotePad). After mastering them, you can get twice the result with half the effort and unexpected results.

2. Create the reg file

The reg file creation process is very simple and can be implemented using any text file editing tool. Before creating a file, remember to remove the "Hide extensions of known file types" Sub-item in "Folder Options" so that you can actually modify the file extension.

 

Extension), and then save. Therefore, an empty reg file is obtained. Of course, you can also choose to directly modify the extension name of the local file. For example, change the extension try.txt to "try. Reg ".

 

 

Double-click to execute the file. The following prompt box is displayed, prompting you whether to modify the registry.

 

3. Reg syntax 3.1 basic syntax

The basic syntax format of reg file content is as follows:

Registryeditorversion

Empty row

[Registrypath1]

"Dataitemname1" = "datatype1: datavalue1"

"Dataitemname2" = "datatype2: datavalue2"

Empty row

[Registrypath2]

"Dataitemname3" = "datatype3: datavalue3"

Empty row

[Registrypath3]

"Dataitemname4" = "datatype4: datavalue4"

 

    • RegistryeditorversionIs the version number of the Windows Registry Editor. In Windows 2000, Windows XP, Windows Server 2003, Windows Vista, and Windows 7, the value is "Windows Registry Editor Version 5.00 ". My system is Windows 7 Service Pack 1 (64-bit) and its value is "Windows Registry Editor Version 5.00 ". In Windows 98 and Windows NT 4.0, the value is "regedit4 ". Windows 2000, Windows XP, and Windows Server 2003 may also be compatible with "regedit4 ".
    • Empty rowIt is used to separate multiple key paths. Each key path can have multiple sub-keys and value items.
    • RegistrypathIt is the key path, which is included in square brackets and separated by a backslash. For example:

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6]

Reg supports recursive creation of new keys (subkeys). You only need to add the desired key (subkeys) to registrypath. For example, use the following statement to create a sub-key try under tcpip6 and create a sub-key ABC under try.

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6\ Try \ ABC]

The Registry consists of keys (or "items"), subkeys (or "subkeys"), and value items.. Let's take a look at the Registry Editor and navigate to the location indicated by the above key path:

    • The hierarchical structure on the left is a key path, which can be understood as a directory. A key is a directory in the branch, and a sub key is a subdirectory in the directory. A sub-key is also a key, because sub-keys can also exist. "Tcpip6" and "linkage" in are keys (subkeys ).
    • "Name-type-Data" on the right is a value item, which can be understood as a file. A key (subkey) can have one or more value items with different names, if the name of a value item is null, the value item is the default value of the key. "Dependonservice" in is the name of the value item, "reg_multi_sz" is the value type, and its value is "TCPIP ".

 

    • DataitemnameIs the name of the value item. If the value does not exist in the registry, it is created. If the value exists, it is overwritten. Note that the value item name must be enclosed in double quotation marks.
    • Datatype,DatavalueIs the value of the value item, where datatype is the value type, datavalue is the specific value, and = ype and dataitemname are connected with "=. The REG_SZ type value must indicate the type of the datatype value, which is caused by double quotation marks, for example, "dataitemname1" = "Microsoft IPv6 protocol driver". Double quotation marks are not required for other types, however, you need to add value types. The value types and specific values are separated by colons, for example, "dataitemname2" = hex (2, "dataitemname3" = hex (7): 5C, 00000006, 00, "dataitemname4" = DWORD.

The Registry has the following types of data:

Display type

(In the editor)

Data Type

Description

REG_BINARY

Binary Number

Binary value, displayed in hexadecimal format

REG_DWORD

Double-Character

A 32-bit binary value is displayed as an 8-bit hexadecimal value or a 10-bit decimal value.

REG_SZ

String

Text string

REG_EXPAND_SZ

Extensible string

 

Reg_multi_sz

Multi-string

String containing multiple text values

In addition, the Registry has other data types, but they are not commonly used:

Reg_dword_big_endian

Reg_dword_little_endian

Reg_full_resource_descriptor

Reg_qword

Reg_file_name

3.2 delete operation syntax

To delete a key (subkey), you only need to add the character "-" to the registrypath header. For example, if you use the following statement to delete the sub-keys try and ABC created above, Reg supports recursive deletion.

Windows Registry Editor Version 5.00

 

[-HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6\ Try]

To delete a value item, you only need to add the character "-" after the equal sign after dataitemname. For example, first create a value item "valueitem" using the first statement below, and then delete the value item using the second statement.

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6 \ try \ ABC]

"Valueitem" = "my value"

 

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6 \ try \ ABC]

"Valueitem" =-

3.3 RENAME operation syntax

To rename a key (sub-key) or value item, delete it first, and then create a new key (sub-key) or value item with a new name.

4. Edit the reg file

ArticleAt first, an empty reg file has been created. To make it work, you need to edit its content. Right-click the file and choose edit or open mode> notepad to open the reg file. Enter the content and save it.

 

The following example shows how to use the reg file. Save the file as follows and run the reg file to obtain the result.

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6 \ try \ ABC]

"Valueitem1" = "my value"

"Valueitem2" = DWORD: 00000014

 

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6 \ try]

"Valueitem3" = hex (7): 5C, 00

 

 

5. Additional knowledge

The Registry has five branches. The names and functions of these five branches are as follows:

Name

Function

Hkey_classes_root

Stores a detailed list of recognizable Windows document types and associated programs

HKEY_CURRENT_USER

Store information set by the current user

HKEY_LOCAL_MACHINE

Includes information about hardware and software installed on a computer

HKEY_USERS

Contains information about users who use computers

Hkey_current_config

This branch contains the current hardware configuration information of the computer.

 

Related Article

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.