Editing the Windows Registry from the Command Prompt lets you add, modify, or delete registry keys and values without opening the Registry Editor GUI. This is useful for scripting, remote administration, or when the GUI is unavailable. You’ll use the built-in reg command, which handles all common registry operations directly from the terminal.
What You’ll Need
- A Windows PC (any recent version: 10, 11, Server).
- Administrator privileges – many registry paths require an elevated Command Prompt.
- Basic knowledge of registry structure: hives (e.g., HKEY_LOCAL_MACHINE), keys (folders), and values (data entries).
- Backup of the registry or the specific key you plan to edit – use
reg exportbefore making changes.
Step-by-Step
- Open an elevated Command Prompt. Press Win, type
cmd, right-click “Command Prompt” and select “Run as administrator.” Confirm the UAC prompt. - Back up the key you’ll edit. Run
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\YourKey" C:\backup.reg(adjust the path and filename). This creates a .reg file you can double-click to restore later. - View current data. Use
reg query "HKLM\SOFTWARE\YourKey"to list all subkeys and values. Add/v ValueNameto see a specific value, or/sto search subkeys recursively. - Add a new key or value. To create a new key:
reg add "HKLM\SOFTWARE\YourKey\NewSubkey". To add a value:reg add "HKLM\SOFTWARE\YourKey" /v NewValue /t REG_SZ /d "data" /f. The/tsets the type (REG_SZ, REG_DWORD, etc.),/dsets the data, and/fforces overwrite without prompting. - Modify an existing value. Use the same
reg addcommand with the existing value name and new data. For example,reg add "HKCU\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\new.jpg" /f. - Delete a value or key. Delete a value with
reg delete "HKLM\SOFTWARE\YourKey" /v ValueName /f. Delete an entire key withreg delete "HKLM\SOFTWARE\YourKey" /f(this removes all subkeys and values). - Copy or move keys. Use
reg copy "HKLM\SOFTWARE\Key1" "HKLM\SOFTWARE\Key2" /s /fto copy recursively. There’s no direct move; copy then delete the source. - Import a .reg file. Run
reg import C:\backup.regto apply a previously exported file. This is useful for restoring or deploying settings. - Verify changes. Run
reg queryagain to confirm the new data appears as expected.
Common Mistakes
- Forgetting to run as administrator. Many hives (especially HKLM) give “Access denied” without elevation.
- Wrong path syntax. Registry paths use backslashes; in Command Prompt, you must quote paths that contain spaces:
"HKLM\SOFTWARE\Microsoft\Windows". - Using the wrong value type. For example, setting a REG_DWORD with string data can cause errors or unexpected behavior. Use
/t REG_DWORD /d 1for numbers. - Omitting the
/fflag. Without it,reg addprompts for confirmation, which can hang scripts. - Deleting a key instead of a value. If you omit
/v,reg deleteremoves the whole key and everything under it.
Tips
- Always export first. A single typo can break system settings. Export the key or the entire hive before editing.
- Use
reg query /sto explore. This shows all subkeys and values, helping you confirm the exact path. - For REG_DWORD, use decimal or hex. You can specify hex with
0xprefix, e.g.,/d 0x1. - Test on a non-critical key first. Try adding a test key under HKCU\Software to get comfortable with syntax.
- Combine commands in a batch file. Put multiple
reglines in a .bat file and run as admin for repeatable setups. - Use
reg add /?for help. The built-in help lists all options and examples.
Troubleshooting
- “Access is denied.” Close Command Prompt and reopen with “Run as administrator.” If you’re already elevated, check that the key isn’t protected by TrustedInstaller – you may need to take ownership first (not covered here).
- “The system cannot find the file specified.” The path is wrong or the key doesn’t exist. Use
reg queryto verify the exact path, including spaces and case (registry is case-insensitive but paths must match). - “Invalid command line parameter.” Check your syntax: every
/v,/t,/dmust be followed by its argument. Also ensure you quote paths with spaces. - Changes don’t take effect. Some settings require a restart or a service restart. For example, changing environment variables requires reopening the Command Prompt or restarting Explorer.
- Registry editor shows different data. If you edited a 32-bit value on 64-bit Windows, the registry redirection may show it under WOW6432Node. Use
reg add /reg:32or/reg:64to target a specific view.
Frequently Asked Questions
Can I edit the registry without admin rights?
You can edit keys under HKEY_CURRENT_USER without elevation, but most system-wide keys under HKEY_LOCAL_MACHINE require administrator privileges.
What is the difference between REG_SZ and REG_DWORD?
REG_SZ is a string (text), while REG_DWORD is a 32-bit number (integer). Use REG_SZ for paths and names, REG_DWORD for numeric values like flags or counts.
How do I delete a registry value with a space in its name?
Quote the value name, e.g., reg delete "HKLM\SOFTWARE\Key" /v "My Value" /f.
Is it safe to edit the registry?
Editing the registry is generally safe if you know exactly what you’re changing. Always back up first, and avoid deleting keys you don’t understand. Incorrect changes can cause system instability.
Can I use Command Prompt to edit registry on a remote computer?
Yes, use reg add \\ComputerName\HKLM\... (or other operations) with the remote computer’s UNC path. You need appropriate permissions and the Remote Registry service running.
How do I restore a backup made with reg export?
Double-click the .reg file and confirm, or run reg import C:\backup.reg from an elevated Command Prompt.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Secure Guest Account on Windows 11: Step-by-Step
- Stop Outlook From Changing Hyperlink Font
- Hiberfil.sys: What It Is & How to Delete It
- How to Make a Mask on Snapchat: Step-by-Step
- How to Factory Reset iPad If You Forgot Password
- Ubuntu in Windows Store: Which Editions Work?