How to edit the registry from the command line
Editing from the command line is one of the ways of editing the registry. Still, before editing the registry, it is always recommended to back up the registry and computer so that if any mistake occurs, we can roll back to a safe state again.
Microsoft state that editing and modifying the Windows registry should be done by admins, IT professionals or under the supervision of advanced users.
Microsoft Windows Vista, XP, 7, 8, 10, and 11 users
Using the "reg" command, Microsoft Windows users of XP and later versions can edit the registry from a command prompt.
The syntax of the command is "C:\>reg".
Microsoft Windows 95, 98, ME, and 2000 users
These Microsoft Windows users can get the registry from the command prompt using the "regedit" command.
To edit the registry through the command prompt, first, start from the command prompt in admin mode.
To do this, type "cmd" in the bottom left search bar of the windows. Right-click on the command prompt and then select on "Run as Administrator" option. Then the command prompt is opened in admin mode. Then one can edit the registry.
Now type “REG /?” in theprompt to get the list of operations specified by the Microsoft.
Registry Operations given by the Microsoft are:
- Add: This adds an entry or subkey to the registry.
- Compare: This compares the two or more than two subkeys or entries in the registry.
- Copy: This copies a registry value to another location.
- Delete: This deletes an entry or subkeys which are selected.
- Export: This exports values, subkeys, and entries by copying and then transfers to other servers.
- Import: Carbons the file contents, that contain shipped entries and values, into the local computer's registry present in the user’s device.
- Load: Writes into different subkey values of saved subkeys.
- Query: Next tier list of subkeys is returned.
- Restore: Saved subkeys and entries are written back into the registry.
- Save: Specified subkeys, entries copy is saved to the registry at a specified file location.
- Unload: Files that are loaded using REG LOAD operation are removed.
Registry operations that user get from the command line helps for getting information about a specific operation that user needs. The following syntax is used to get help
REG <Operation> /? |
Example: For add operation, if a user wants help, type REG ADD /?
Then it returns all the parameters, syntax, and examples used for add operation.
Add value to a registry
Command: reg add HKLM\software\sisl\dataoprt /v server /d 192.168.1.6 /f /reg:64
/v for a key value name
/d for the value of key
/f means force add
/reg:64 for 64 bit machine
/reg:32 for 32 bit machine
Change the existing value in a registry
Command: reg add HKLM\software\sisl\dataoprt /v server /d anyname /f /reg:64
Delete a value
Command: reg delete HKLM\software\sisl\dataport /v server /f /reg:64
REG operations
Operations and Syntax
Operation | Syntax |
Add | REG ADD <Key_Name> [{/v Value_Name | /ve}] [/t DataType] [/s Separator] [/d Data] [/f] |
Compare | REG COMPARE <Key_Name1> <Key_Name2> [{/v Value_Name | /ve}] [{/oa | /od | /os | on}] [/s] |
Copy | REG COPY <Key_Name1> <Key_Name2> [/s] [/f] |
Delete | REG DELETE <Key_Name> [{/v Value_Name | /ve | /va}] [/f] |
Export | REG EXPORT Key_Name File_Name [/y] |
Import | REG IMPORT File_Name |
Load | REG LOAD KeyName File_Name |
Query | REG QUERY <Key_Name> [{/v <Value_Name> | /ve}] [/s] [/se <Separator>] [/f <Data>] [{/k | /d}] [/c] [/e] [/t <Type>] [/z] |
Restore | REG RESTORE <Key_Name> <File_Name> |
Save | REG SAVE <Key_Name> <File_Name> [/y] |
Unload | REG UNLOAD <Key_Name> |
Parameter and its Description
Parameter | Description |
<KeyName> | The full path of the entry or subkey is stated, which is to be added. The key name should contain a valid root key like HKLM, HKU, HKCC, HKCR, HKCU |
/v <ValueName> | States the registry entry name to be added under the specified subkey. |
/ve | The registry to be added new to the registry is given a null value. |
/t <Type> | Registry types that are to be typed are stated. If nothing is specified, each and every type is searched. |
/s <Separator> | The character to be used for separating the multiple instances of data for the REG_MULTI_SZ data type is stated. The default separator is “\0”(null) when nothing is detailed. |
/d <Data> | Data for new registry entries is stated. |
/f | With this registry, an entry is added with prompting for confirmation. |
/oa | Only differences are listed by default. This states that all matches and differences are listed. |
/od | States that differences are only listed. /od is the default behavior. |
/os | States are only matched are displayed. Only differences are listed by default. |
/on | States that anything is not displayed. Only differences are listed by default. |
/s | all subkeys and entries are compared recursively. |
/va | Under the specified subkey, all entries are deleted, and specified subkeys are not deleted. |
<FileName> | Used to specify the name and path of a file to be created while undergoing an operation. The ".reg" extension must be there for a file. |
/y | With the name "FileName," existing file is overwritten without prompting for confirmation. |
/se <Separator> | In the value name type “REG_MULTI_SZ”, this parameter is used to specify the value separator to search. If no separator is specified, \0 is used. |
/f <Data> | States the pattern or data to search. |
/k | States that the search should be done in key names only. |
/d | States that the search should be done in data only. |
/c | Matches are case insensitive, but this states that queries are case sensitive. |
/e | States that only the exact matched values should be returned. |
/z | In the search results for registry type, it states to contain the numeric equivalent. |
/? | At the command prompt, it will output the help for "reg" operation. |