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
- Open a command prompt with appropriate privileges. Press
Win + R, typecmd, and pressCtrl + Shift + Enterto run as Administrator. Alternatively, right-click the Start button and select “Terminal (Admin)”. - Identify the full registry path. For example,
HKEY_LOCAL_MACHINE\SOFTWARE\MyApp. Use the abbreviated root key names:HKLM,HKCU,HKCR,HKU, orHKCC. - Construct the
reg addcommand. 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/fflag forces the operation without prompting for confirmation. - Format the binary data correctly. The
/dparameter expects hexadecimal digits separated by spaces, with no commas or other delimiters. For example, to write the bytes0x01,0x02,0xFF, use:/d 01 02 ff. You can also use uppercase or lowercase hex digits. - Run the command. Press Enter. If successful, you will see the message:
The operation completed successfully. - 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_BINARYflag. Without it,reg adddefaults toREG_SZ, which will store the data as a string, not binary. - Using commas or dashes in the hex data. The
/dparameter only accepts spaces between hex pairs. Incorrect delimiters cause a syntax error. - Forgetting the
/fflag. 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 adddoes not create intermediate keys. If the path is wrong, you get an error. - Not running as Administrator. Writing to
HKLMwithout admin rights results in “Access is denied.”
Tips
- Back up the registry before making changes. Use
reg export <key> backup.regto save the current state. - Use lowercase hex digits if you prefer; Windows is case-insensitive.
- For empty binary data (zero bytes), use
/dwith no data? Actually, you must provide at least one byte; to create an empty binary value, use/d 00or use/dwith nothing after it? The correct way is to use/dfollowed by nothing? In practice, you can use/d 00for a single zero byte, or usereg addwith/dand no data? It is safer to use/d 00for 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 queryto confirm the type showsREG_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 usereg add <key> /veto 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_BINARYflag. 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
- Install Android Apps on SD Card: Full Guide
- Why Is My Standby Red on iPhone? Fixes
- Fix Error 0x800703e6: 5 Working Methods
- How to Use Multiple Desktops on Mac (Spaces Guide)
- How to Alter Galaxy Note 8 Text Message App
- Set iPhone Media Volume Limit: Step-by-Step