reg - Work with the Registry

Maintained on

The reg command works with the Windows registry. It lets you view, add, change, and delete keys and values from Command Prompt or a batch file, just as you would in Registry Editor (regedit).

It is useful when you want to automate a settings change or apply the same setting to several computers.

Be careful when editing the registry

Changing the registry incorrectly can stop Windows or applications from working properly. Always back up with reg export before you change or delete anything.

Registry Basics

The registry is a database that stores settings for Windows and applications. It consists of keys, which work like folders, and the values (name, type, and data) stored in them.

With the reg command, you specify a key with a path like this:

HKEY_CURRENT_USER\Software\MyApp

For the root key at the start of the path, you can use these abbreviations:

AbbreviationFull nameContents
HKLMHKEY_LOCAL_MACHINESettings that apply to the whole computer
HKCUHKEY_CURRENT_USERSettings for the current user only
HKCRHKEY_CLASSES_ROOTFile associations and similar settings
HKUHKEY_USERSSettings for all users
HKCCHKEY_CURRENT_CONFIGThe current hardware configuration
Keys that need administrator rights to write

HKCU holds the current user’s settings, so you can change it with normal privileges. Writing to HKLM, however, requires administrator rights. Without them, you get “Access is denied.” See the related articles for details.

Basic Syntax of the reg Command

reg <operation> <key name> [options]

The available operations are listed below. This article focuses on the commonly used query, add, delete, export, and import.

OperationDescription
queryDisplay keys and values
addAdd keys and values (existing values are overwritten after confirmation)
deleteDelete keys and values
exportWrite a key to a .reg file
importLoad the contents of a .reg file into the registry
copyCopy a key to another location
compareCompare two keys or values
save / restoreSave and restore a key as a binary file
load / unloadLoad a saved hive into the registry, or unload it
Quote paths that contain spaces

If a key name or value name contains spaces, enclose it in double quotation marks ("), as in "HKCU\Software\My App".

Display Keys and Values (reg query)

Display the contents of a key

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"

This lists the values and subkeys directly under the specified key. This key holds the apps that start automatically when you sign in.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
OneDrive REG_SZ “C:\Users\taro\AppData\Local\Microsoft\OneDrive\OneDrive.exe” /background
C:\users\user>

Each line shows the value name, the value type, and the data, in that order.

Display only a specific value

Use /v to specify the value name.

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
ProductName REG_SZ Windows 10 Pro
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

To display the default value, which has no name, use /ve instead of /v.

Display or search including subkeys

Add /s to display everything, including subkeys. Combine it with /f to search for text.

Display
reg query "HKCU\Software\MyApp" /s
Search
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /s /f Chrome

query options

OptionDescription
/v nameDisplay only the value with the specified name
/veDisplay the default value (no name)
/sDisplay recursively, including subkeys
/f textText to search for (partial match, case-insensitive by default)
/kLimit the /f search to key names
/dLimit the /f search to data
/cMake the search case-sensitive
/eMatch only exact results
/t typeDisplay only values of the specified type

Value Types

Every value has a type, which you specify with /t in reg add.

TypeDescription
REG_SZA string (this is the default if you omit the type)
REG_EXPAND_SZA string that can contain environment variables such as %PATH%
REG_MULTI_SZMultiple strings (separated by \0 by default)
REG_DWORDA 32-bit number, often used for on/off settings (0 and 1)
REG_QWORDA 64-bit number
REG_BINARYBinary data
REG_NONENo type

Add or Change Keys and Values (reg add)

reg add <key name> [/v name | /ve] [/t type] [/d data] [/f]

If the key does not exist, it is created along with any intermediate keys. If the specified value already exists, it is overwritten after confirmation (add /f to overwrite without confirmation).

Add
reg add "HKCU\Software\MyApp" /v UserName /t REG_SZ /d "taro"
Add
reg add "HKCU\Software\MyApp" /v Enabled /t REG_DWORD /d 1

When it succeeds, the message “The operation completed successfully.” appears.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>reg add "HKCU\Software\MyApp" /v Enabled /t REG_DWORD /d 1
The operation completed successfully.
C:\users\user>

add options

OptionDescription
/v nameName of the value to add
/veSet the default value (no name)
/t typeValue type (REG_SZ if omitted)
/d dataData to set (for REG_DWORD, a decimal number or a hexadecimal number starting with 0x)
/s separatorOne character that separates multiple strings in REG_MULTI_SZ (default \0)
/fOverwrite an existing value without confirmation
Without /f, you are asked to confirm the overwrite

If you run reg add on a value that already exists, a confirmation message (Yes/No) asks whether to overwrite it, and the command waits for input. In a batch file that runs automatically, the script stops unless you add /f.

Example: Show file extensions

The setting that shows file extensions in File Explorer is stored in a value named HideFileExt. Setting it to 0 shows extensions.

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v HideFileExt /t REG_DWORD /d 0 /f

The setting takes effect after you reopen File Explorer or sign in again.

Delete Keys and Values (reg delete)

Delete
reg delete "HKCU\Software\MyApp" /v UserName /f
Delete
reg delete "HKCU\Software\MyApp" /f
OptionDescription
/v nameDelete only the specified value
/veDelete the default value (no name)
/vaDelete all values in the key (subkeys remain)
/fDelete without confirmation
If you forget /v, the whole key is deleted

If you run reg delete without any of /v, /ve, or /va, the key and all of its subkeys and values are deleted. With /f, no confirmation appears and you cannot undo it. Check the key name and whether /v is present before you run it.

Back Up and Restore (reg export / reg import)

Before you change the registry, write the target key to a .reg file.

Back
reg export "HKCU\Software\MyApp" "%USERPROFILE%\Desktop\myapp-backup.reg"

If a file with the same name exists, you are asked whether to overwrite it. Add /y to overwrite without confirmation.

Restore
reg import "%USERPROFILE%\Desktop\myapp-backup.reg"
You can also double-click a .reg file to import it

Double-clicking an exported .reg file also imports its contents into the registry. Note that reg import only adds or overwrites the keys and values written in the file. It does not delete values that were added after the backup. To return completely to the original state, delete the target key with reg delete first, and then import.

Using It in Batch Files

Read a value into a variable

The output of reg query has the form value name type data. You can split it on whitespace with for /f and extract the data.

get-product-name.cmd
@echo off

set KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion

for /f "tokens=2*" %%a in ('reg query "%KEY%" /v ProductName ^| find "ProductName"') do set PRODUCT=%%b

echo Product name: %PRODUCT%

tokens=2* assigns the second item (the type) to %%a and everything after it (the data) to %%b. Even if the data contains spaces, %%b captures it all. However, if the value name itself contains spaces, the item positions shift and this method does not work.

Check whether a key or value exists

reg query returns exit code 1 if the target does not exist. You can use this to check for existence.

check-key.cmd
@echo off

reg query "HKCU\Software\MyApp" /v Enabled >nul 2>&1
if errorlevel 1 (
  echo No setting found. Registering the default.
  reg add "HKCU\Software\MyApp" /v Enabled /t REG_DWORD /d 1 /f >nul
) else (
  echo Setting found.
)

>nul 2>&1 suppresses both standard output and error output.

32-bit and 64-bit Registry Views

On 64-bit Windows, some keys such as HKLM\SOFTWARE are split so that 32-bit apps see a separate location (WOW6432Node). The reg command has options to choose which view to operate on.

OptionDescription
/reg:32Operate on the 32-bit registry view
/reg:64Operate on the 64-bit registry view
reg query "HKLM\SOFTWARE\MyApp" /reg:32

You may need to specify this when working with settings that a 32-bit app reads and writes.

Summary

What you want to doCommand
Display the contents of a keyreg query "key name"
Display a specific valuereg query "key name" /v value name
Search by textreg query "key name" /s /f search text
Add or change a valuereg add "key name" /v name /t type /d data /f
Delete a valuereg delete "key name" /v name /f
Delete a keyreg delete "key name" /f
Make a backupreg export "key name" filename.reg
Restore from a backupreg import filename.reg

Practice Questions

Practice Problem

Which command deletes only the value named Enabled in the HKCU\Software\MyApp key, without asking for confirmation?

回答がサーバーに送信されることはありません
Practice Problem

Which statement about the reg command is correct?

回答がサーバーに送信されることはありません
#Command Prompt #Batch Files #Command Line #Commands #Registry #Backup