REG.exe – Windows CMD Command

Read, Set or Delete registry keys and values, save and restore from a .REG file.

Any of the above commands can be run against a remote machine by adding \\MachineName to the command line, assuming the Remote Registry Service is running.

Registry paths which contain a space must be enclosed by quotation marks:
“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList\”
It is easy to miss one space in a long path so it is not a bad practice to simply surround all registry paths with quotes.

Depending on the registry permissions, REG ADD may require running REG.exe from an elevated command prompt.
Registry data stored under HKCU will be visible and writable by the currently logged in user.
Registry data stored under HKLM will be visible to all users and writable only by administrators.

REG RESTORE has a tendency not to work, possibly due to firewall issues, EXPORT and IMPORT are much more reliable.

Backslash characters

The REG command will interpret \ as an escape for the character that immediately follows it.
To include a quote mark (“) in the data, prefix it with the escape character e.g. Here is \” a quote

This can cause problems with quoted directory paths because \” at the end of the line will be escaped.

To save a directory path with a trailing backslash (\) requires adding a second backslash to ‘escape’ the escape
so for example instead of “C:\My Docs\” use “C:\My Docs\\”

Activate

To activate registry changes in HKEY_CURRENT_USER without logging off:
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
n.b. this is an unsupported hack, with a good chance of failing in the future – details on oldnewthing
The SetWallpaper.exe utility is an alternative.

Elevation

Unlike REGEDIT, REG.exe does not always require elevation
When adding an item to HKCU, REG will be automatically manifested “asInvoker”, and will work without elevation,
when adding an item to HKLM then it does need to be run elevated.

Return codes (ERRORLEVEL)

0 = Success, the result is identical
1 = Failed
2 = Success, the result is different

You may also like...

1 Response

  1. zortilonrel says:

    certainly like your web site however you have to test the spelling on several of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the truth on the other hand I will surely come back again.

Leave a Reply

Your email address will not be published.