sodcalculator

10 Tech How-To

Edit Windows Registry via Command Prompt

Guide 10-56508 · Updated · Step by step

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 export before making changes.

Step-by-Step

  1. Open an elevated Command Prompt. Press Win, type cmd, right-click “Command Prompt” and select “Run as administrator.” Confirm the UAC prompt.
  2. 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.
  3. View current data. Use reg query "HKLM\SOFTWARE\YourKey" to list all subkeys and values. Add /v ValueName to see a specific value, or /s to search subkeys recursively.
  4. 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 /t sets the type (REG_SZ, REG_DWORD, etc.), /d sets the data, and /f forces overwrite without prompting.
  5. Modify an existing value. Use the same reg add command 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.
  6. Delete a value or key. Delete a value with reg delete "HKLM\SOFTWARE\YourKey" /v ValueName /f. Delete an entire key with reg delete "HKLM\SOFTWARE\YourKey" /f (this removes all subkeys and values).
  7. Copy or move keys. Use reg copy "HKLM\SOFTWARE\Key1" "HKLM\SOFTWARE\Key2" /s /f to copy recursively. There’s no direct move; copy then delete the source.
  8. Import a .reg file. Run reg import C:\backup.reg to apply a previously exported file. This is useful for restoring or deploying settings.
  9. Verify changes. Run reg query again 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 1 for numbers.
  • Omitting the /f flag. Without it, reg add prompts for confirmation, which can hang scripts.
  • Deleting a key instead of a value. If you omit /v, reg delete removes 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 /s to 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 0x prefix, 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 reg lines 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 query to 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, /d must 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:32 or /reg:64 to 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

The whole Tech How-To bed →