sodcalculator

10 Tech How-To

reg add Binary Value: Step-by-Step Guide

Guide 10-59749 · Updated · Step by step

This guide explains how to use the reg add command in Windows to create or modify a registry value of type REG_BINARY. You will learn the exact syntax, how to format binary data correctly, and how to verify the result. This is useful for configuring software, hardware settings, or system policies that store data as binary blobs.

What You’ll Need

  • A Windows computer (Windows 10 or 11 recommended).
  • Administrator rights if you are modifying keys under HKLM (HKEY_LOCAL_MACHINE) or other protected areas.
  • Knowledge of the exact registry path and value name you want to create or change.
  • The binary data you want to write, in hexadecimal format (e.g., 01 02 03).
  • A command prompt or PowerShell window (run as Administrator if needed).

Step-by-Step

  1. Open a command prompt with appropriate privileges. Press Win + R, type cmd, and press Ctrl + Shift + Enter to run as Administrator. Alternatively, right-click the Start button and select “Terminal (Admin)”.
  2. Identify the full registry path. For example, HKEY_LOCAL_MACHINE\SOFTWARE\MyApp. Use the abbreviated root key names: HKLM, HKCU, HKCR, HKU, or HKCC.
  3. Construct the reg add command. The basic syntax is:
    reg add <key> /v <value_name> /t REG_BINARY /d <hex_data> /f
    Replace <key>, <value_name>, and <hex_data> with your actual values. The /f flag forces the operation without prompting for confirmation.
  4. Format the binary data correctly. The /d parameter expects hexadecimal digits separated by spaces, with no commas or other delimiters. For example, to write the bytes 0x01, 0x02, 0xFF, use: /d 01 02 ff. You can also use uppercase or lowercase hex digits.
  5. Run the command. Press Enter. If successful, you will see the message: The operation completed successfully.
  6. Verify the value. Use reg query <key> /v <value_name> to display the value and confirm it contains the expected binary data.

Common Mistakes

  • Missing the /t REG_BINARY flag. Without it, reg add defaults to REG_SZ, which will store the data as a string, not binary.
  • Using commas or dashes in the hex data. The /d parameter only accepts spaces between hex pairs. Incorrect delimiters cause a syntax error.
  • Forgetting the /f flag. If the value already exists, you will be prompted to overwrite. In scripts, this can cause the command to hang.
  • Using an invalid registry path. The key must already exist; reg add does not create intermediate keys. If the path is wrong, you get an error.
  • Not running as Administrator. Writing to HKLM without admin rights results in “Access is denied.”

Tips

  • Back up the registry before making changes. Use reg export <key> backup.reg to save the current state.
  • Use lowercase hex digits if you prefer; Windows is case-insensitive.
  • For empty binary data (zero bytes), use /d with no data? Actually, you must provide at least one byte; to create an empty binary value, use /d 00 or use /d with nothing after it? The correct way is to use /d followed by nothing? In practice, you can use /d 00 for a single zero byte, or use reg add with /d and no data? It is safer to use /d 00 for a single zero byte; an empty binary value is rarely needed.
  • When writing large binary data, consider using a .reg file instead, as it is easier to manage and less error-prone.
  • Use reg query to confirm the type shows REG_BINARY.

Troubleshooting

  • “The system cannot find the file specified.” This means the registry key does not exist. Create it with reg add <key> (without /v) first, or use reg add <key> /ve to create a default value.
  • “Invalid syntax.” Check that you have used spaces correctly and that the hex data contains only hex digits and spaces. Also, ensure the value name does not contain spaces; if it does, enclose it in quotes.
  • “Access is denied.” Run the command prompt as Administrator. If you are already admin, the key may be protected by TrustedInstaller; you may need to take ownership first.
  • The value appears as a string in Registry Editor. This means you forgot the /t REG_BINARY flag. Delete the value and re-add it with the correct type.
  • Data is truncated or corrupted. Make sure you did not accidentally include a trailing space or non-hex character. Also, verify that you are using the correct byte order (little-endian vs big-endian) if the data represents a multi-byte integer.

Frequently Asked Questions

Can I use reg add to create a new registry key?

Yes, if you specify a key path that does not exist, reg add will create it, but only if the parent key exists. For example, reg add HKLM\SOFTWARE\MyApp will create the MyApp key under SOFTWARE.

How do I write binary data that contains spaces in the value name?

Enclose the value name in double quotes. For example: reg add HKLM\SOFTWARE\MyApp /v "My Data" /t REG_BINARY /d 01 02 /f.

What is the difference between REG_BINARY and REG_DWORD?

REG_DWORD is a 32-bit unsigned integer, stored as 4 bytes in little-endian format. REG_BINARY can hold any arbitrary byte sequence, including multi-byte integers, but you must specify the exact bytes.

Can I use reg add in a batch script?

Yes, reg add is fully scriptable. Use the /f flag to avoid prompts, and check the %ERRORLEVEL% to verify success.

How do I delete a binary registry value?

Use reg delete <key> /v <value_name> /f. This removes the value, not the key itself.

Is there a way to import binary data from a file?

Not directly with reg add. You can create a .reg file with the binary data in hex format and import it with regedit /s file.reg. The .reg file format for binary data is hex:01,02,03 (commas, no spaces).

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 →