How to Convert Registry Files to their Batch File Equivalents

This Tutorial is a work in progress and is closed for replies. After its completion, it will be opened for replies. In the meantime, if you have any suggestions or spot any glaring omissions/errors, please feel free to PM and/or VM me. Thankyou.

This tutorial will show you the basics of converting registry files so that you can run them as a batch file. This is particularly useful for those files which need administrative privileges to be merged into the registry.

The default behaviour of .reg files is to merge into the registry. However, the merge option only operates with the same privileges as the currently logged in user and, unlike running a program, this cannot be elevated to operate with administrative privileges. Basically, modifying registry keys in the HKCR and HKLM branches requires doing so from within an administrative account or from an equivalent batch file that is run with administrative privileges. This is because information there has a system-wide scope. The HKCU branch is different, and the data there can be modified from within a standard or an administrative account, since the information there pertains to the individual user and not the system as a whole.

The examples shown here are just that - they are to show examples and are not designed to carry out any specific function.

All examples are located in the following key:

HKEY_CURRENT_USER\Test (.reg file) or HKCU\Test (.bat file)

Actual files will pertain to different sections of the registry, and the equivalent handles (roots) are as follows (.reg file > .bat file):

HKEY_CLASSES_ROOT > HKCR (administrative privileges required)
HKEY_CURRENT_USER > HKCU
HKEY_LOCAL_MACHINE > HKLM (administrative privileges required)
HKEY_USERS > HKU
HKEY_CURRENT_CONFIG > HKCC

The vast majority of registry edits will pertain to one or more of the first three roots listed above.

Now for the examples themselves. They will be displayed in the form of code boxes, with the .reg being shown first followed by the .bat equivalent.

Code:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Test]
@=""
Code:
@ ECHO OFF
REG ADD "HKCU\Test" /ve /f
Code:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Test]
@="Some data"
Code:
@ECHO OFF
REG ADD "HKCU\Test" /ve /t REG_SZ /d "Some data" /f