Windows Command Prompt Registry Editing
last modified July 14, 2025
The Windows Registry is a hierarchical database storing system and application settings. It contains configurations for hardware, software, users, and preferences. Registry editing should be done carefully as incorrect changes can make the system unstable.
The Command Prompt provides powerful tools for registry manipulation. The REG command allows viewing, adding, modifying, and deleting registry keys and values. This is useful for scripting and remote administration. Registry operations require administrative privileges to modify most keys.
Registry keys are organized in a tree structure with five root keys: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and HKEY_CURRENT_CONFIG. Each key can contain subkeys and named values that store configuration data.
This tutorial covers registry editing through Command Prompt. We'll explore basic operations, data types, exporting/importing, and common use cases. Always back up the registry before making changes. These skills are valuable for system administrators and power users.
Basic Registry Structure
The Windows Registry is organized hierarchically like a file system. Root keys contain subkeys which may contain further subkeys or values. Each value has a name, data type, and stored data.
@echo off echo Listing registry keys... reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion reg query HKCU\Software\Microsoft\Windows\CurrentVersion
This script demonstrates viewing registry keys under common locations. The reg query command displays subkeys and values for a specified path.
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
Lists all values under the Windows CurrentVersion key in HKEY_LOCAL_MACHINE. HKLM is a commonly accessed root key for system-wide settings.
reg query HKCU\Software\Microsoft\Windows\CurrentVersion
Shows the same path under HKEY_CURRENT_USER for user-specific settings. HKCU contains preferences that override HKLM settings for the current user.
C:\>view_reg.bat Listing registry keys... HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion ProgramFilesDir REG_EXPAND_SZ %ProgramFiles% CommonFilesDir REG_EXPAND_SZ %ProgramFiles%\Common Files SystemRoot REG_EXPAND_SZ C:\Windows ...
Output shows registry values with their types and data. The exact output varies based on Windows version and configuration.
Adding Registry Keys and Values
New registry keys and values can be added using the reg add command. This is useful for configuring applications or system settings.
@echo off echo Adding registry test key... reg add HKCU\Software\MyTestApp /v Version /t REG_SZ /d "1.0" /f reg add HKCU\Software\MyTestApp\Settings /v LogLevel /t REG_DWORD /d 2 /f reg query HKCU\Software\MyTestApp
This script creates a new application key with values. The /f flag forces overwrite without prompting. Always verify the key path before adding.
reg add HKCU\Software\MyTestApp /v Version /t REG_SZ /d "1.0" /f
Creates a string (REG_SZ) value named "Version" with data "1.0". The /v specifies the value name, /t the type, and /d the data.
reg add HKCU\Software\MyTestApp\Settings /v LogLevel /t REG_DWORD /d 2 /f
Adds a DWORD value for logging level under a Settings subkey. DWORD values store 32-bit numbers for options like enable/disable flags.
C:\>add_reg.bat Adding registry test key... The operation completed successfully. The operation completed successfully. HKEY_CURRENT_USER\Software\MyTestApp Version REG_SZ 1.0 HKEY_CURRENT_USER\Software\MyTestApp\Settings LogLevel REG_DWORD 0x2
The script creates the new keys and values, then displays them. The 0x2 is hexadecimal representation of the DWORD value 2.
Modifying Registry Values
Existing registry values can be modified using the reg add command with the same syntax as adding. This allows updating configuration values.
@echo off echo Modifying registry values... reg add HKCU\Software\MyTestApp /v Version /t REG_SZ /d "1.1" /f reg add HKCU\Software\MyTestApp\Settings /v LogLevel /t REG_DWORD /d 3 /f reg query HKCU\Software\MyTestApp
This script updates the values created in the previous example. The same reg add command is used for both adding and modifying values.
reg add HKCU\Software\MyTestApp /v Version /t REG_SZ /d "1.1" /f
Updates the Version string value from "1.0" to "1.1". The /f flag is required to modify existing values without confirmation.
reg add HKCU\Software\MyTestApp\Settings /v LogLevel /t REG_DWORD /d 3 /f
Changes the LogLevel from 2 to 3. DWORD values are often used for numeric settings like verbosity levels or timeout values.
C:\>modify_reg.bat Modifying registry values... The operation completed successfully. The operation completed successfully. HKEY_CURRENT_USER\Software\MyTestApp Version REG_SZ 1.1 HKEY_CURRENT_USER\Software\MyTestApp\Settings LogLevel REG_DWORD 0x3
Output shows the updated values. The changes take effect immediately unless the application caches registry values.
Deleting Registry Keys and Values
The reg delete command removes registry keys or specific values. This is useful for cleaning up settings or troubleshooting.
@echo off echo Deleting registry test values... reg delete HKCU\Software\MyTestApp /v Version /f reg delete HKCU\Software\MyTestApp\Settings /v LogLevel /f reg query HKCU\Software\MyTestApp
This script removes the values created earlier while keeping the keys. The /f flag suppresses confirmation prompts for silent operation.
reg delete HKCU\Software\MyTestApp /v Version /f
Deletes the Version value from the MyTestApp key. The key itself remains intact unless explicitly deleted with /ve for the default value.
reg delete HKCU\Software\MyTestApp\Settings /v LogLevel /f
Removes the LogLevel value from the Settings subkey. The subkey structure persists until all values are deleted and the key is removed.
C:\>delete_reg.bat Deleting registry test values... The operation completed successfully. The operation completed successfully. HKEY_CURRENT_USER\Software\MyTestApp ERROR: The system was unable to find the specified registry key or value.
After deletion, querying shows the values are gone. The ERROR appears because we didn't add other values to display.
Exporting and Importing Registry Keys
Registry keys can be exported to .reg files for backup or transfer. These files can later be imported to restore or apply settings.
@echo off echo Exporting registry key... reg export HKCU\Software\MyTestApp mytestapp.reg echo Deleting original key... reg delete HKCU\Software\MyTestApp /f echo Importing registry key... reg import mytestapp.reg reg query HKCU\Software\MyTestApp
This script demonstrates a complete export-delete-import cycle. .reg files are text files that can be edited before importing.
reg export HKCU\Software\MyTestApp mytestapp.reg
Creates a .reg file containing all values under MyTestApp. The export includes the full key path and all descendant keys.
reg delete HKCU\Software\MyTestApp /f
Removes the entire MyTestApp key and all subkeys. This simulates losing the settings or needing to reset them.
reg import mytestapp.reg
Restores the registry key from the exported file. Import merges the contents, preserving other values in the same key.
C:\>export_import.bat Exporting registry key... The operation completed successfully. Deleting original key... The operation completed successfully. Importing registry key... The operation completed successfully. HKEY_CURRENT_USER\Software\MyTestApp Version REG_SZ 1.1
The output shows the successful round-trip of registry data. The imported key matches the original exported structure.
Source
Microsoft REG Command Reference
This tutorial covered essential registry editing techniques through Command Prompt. Always back up the registry before making changes and test modifications in a controlled environment first.