reg.exe from the command line
Query, add, delete, export, save, restore, load and compare registry data with the built-in reg command.
reg.exe ships with every Windows release, works in Server Core, in WinPE and from any script, and can target remote computers. Run it elevated for HKLM writes.
The subcommands
| Command | Does |
|---|---|
reg query | Read keys and values; /s recurses, /f searches, /v picks a value |
reg add | Create a key or set a value (/t type, /d data, /f no prompt) |
reg delete | Remove a value (/v), all values (/va) or the key |
reg copy | Copy a key to another path, optionally on another computer |
reg export / reg import | Write or read a .reg text file |
reg save / reg restore | Write a branch to a binary hive file / overwrite a branch from one |
reg load / reg unload | Mount an offline hive file under HKLM or HKU and detach it |
reg compare | Diff two keys, locally or across computers |
reg flags | View or set virtualization flags on HKLM\SOFTWARE subkeys |
Everyday examples
:: read one value
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections
:: find every value or key containing "Citrix" under SOFTWARE (keys, values and data)
reg query HKLM\SOFTWARE /f Citrix /s
:: set a DWORD (decimal) without a prompt
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
:: set a multi-string (\0 separates entries)
reg add "HKLM\SOFTWARE\FSLogix\Profiles" /v VHDLocations /t REG_MULTI_SZ /d "\\fs01\profiles\0\\fs02\profiles" /f
:: delete a value
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate /f
:: 32-bit view on 64-bit Windows
reg query HKLM\SOFTWARE\Contoso /reg:32
Backup before a change
reg export "HKLM\SOFTWARE\Citrix\VirtualDesktopAgent" C:\Backup\vda-before.reg /y
reg save "HKLM\SOFTWARE\Citrix\VirtualDesktopAgent" C:\Backup\vda-before.hiv /y
Use export for human-readable files you can diff and partially re-import. Use save/restore for an exact binary copy that includes security descriptors; reg restore replaces the whole branch.
Remote computers
Prefix the key with \\computer\. Remote access only reaches HKLM and HKU and needs the Remote Registry service on the target (see Remote registry).
reg query \\srv01\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp /v PortNumber
reg compare \\srv01\HKLM\SOFTWARE\Contoso \\srv02\HKLM\SOFTWARE\Contoso /s
Exit codes in scripts
reg returns 0 on success and 1 on failure; reg compare returns 0 when identical and 2 when different. Check %ERRORLEVEL% (cmd) or $LASTEXITCODE (PowerShell).
Reference: reg command reference (Microsoft Learn).