REG - CMD
Overview
The REG
command in Windows Command Prompt is a powerful tool used for manipulating the registry. It allows users to add, delete, and query registry keys and values, making it essential for system administrators and power users for script automation, system tweaks, and troubleshooting.
Syntax
The basic syntax of the REG
command is as follows:
REG OPERATION [Parameter1] [Parameter2] [...]
Where OPERATION
can be one of the following:
ADD
DELETE
QUERY
COPY
SAVE
LOAD
UNLOAD
RESTORE
COMPARE
EXPORT
IMPORT
Each operation might require different parameters. Ensure you refer to the specific operation for exact parameter requirements.
Options/Flags
- ADD: Adds a new subkey or entry to the registry.
/v
: Specifies the entry name./t
: Specifies the type (e.g.,REG_SZ
)./s
: Specifies separator in data string (default is\0
).
- DELETE: Deletes a subkey or entries from the registry.
/v
: Specifies the entry to remove./f
: Forces the deletion without prompt.
- QUERY: Displays the data in a registry key or entries.
/v
: Queries for a specific entry./s
: Queries all subkeys and entries.
- EXPORT: Exports a registry key to a file.
/y
: Overwrites an existing file without prompt.
- IMPORT: Imports registry data from a file.
- SAVE: Saves a registry key and its subkeys to a hive file.
- LOAD: Loads a hive into the registry.
- UNLOAD: Removes a hive from the registry.
- COPY: Copies a registry key to another path.
- RESTORE: Restores registry data from a saved hive file.
Examples
Adding a Registry Key:
REG ADD HKLM\Software\MyCo /v Data /t REG_BINARY /d fe340ead
Deleting a Registry Entry:
REG DELETE HKLM\Software\MyCo /v Data /f
Querying the Registry:
REG QUERY HKLM\Software\MyCo
Exporting a Registry Key:
REG EXPORT HKLM\Software\MyCo backup.reg
Common Issues
- Access Denied: Ensure you have sufficient privileges to modify the registry keys.
- Syntax Errors: Double-check the syntax as missing parameters or incorrect flags can cause the command to fail.
Integration
Combining with Other Commands:
You can combine REG
with other commands like FOR
for looping through returned keys, or using IF
for conditional operations.
Example Script:
FOR /F "tokens=*" %%G IN ('REG QUERY HKCU\Software\Classes') DO (
REG ADD %%G /v Checked /t REG_SZ /d Yes
)
Related Commands
- CMDKEY: Manages stored usernames and passwords.
- SETX: Used to set environment variables.
Further Reading:
- Microsoft’s official documentation: Reg Command Reference provides complete details and examples.