Formatting .reg files for use with command-line REGEDIT

Registry entries can be added, changed, or deleted using REGEDIT. REGEDIT can also be run from the command-line to allow the modification of registry entries as part of a script. The syntax is simply:

   regedit regfile.reg

The user will be prompted to add the registry settings. Note: remember that Users will only have the right to add settings to HKEY_CURRENT_USER by default. To turn off the prompt you can run regedit silenced by adding the /s switch:

   regedit /s regfile.reg

As the exact format of a registry file can be tricky, one tip is to manually export the desired registry key using the REGEDIT GUI, then edit the exported .reg file using Notepad or another text editor to reflect the desired changes.

To add or change a registry setting, the format of your .reg file should look something like this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software]
"test"="My new value"

In this example, if the value "test" already exists, it will be changed to "My new value". If the value does not exist, it will be created and assigned "My new value".

To delete a registry key (folder), you can preface the key path with a minus sign ("-") inside the leading square bracket. The format of your .reg file should look something like this:

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Key To Be Deleted]

To delete a registry value, you must set the value equal to a minus sign ("-") without quotes. The format of your .reg file should look something like this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software]
"test"=-

If you set the value to "" (empty quotes) the data will be blanked out, but the value itself will still exist in the registry. If you set the value to "-" (minus with quotes) the data will be changed to a minus sign.


Author: ASAK
Created: Nov 1 2005 (last modified Nov 28 2005)
Categories: Windows
TechByte #80

Warning: By visiting this site and/or by using any information contained herein, you agree to the Techbytes.ca terms of use.



Add a comment about this TechByte

If you wish to add a comment regarding this TechByte, please use the form below. Please note that by submitting comments using this form you are allowing all of the information submitted to be visible on this website. Any comments submitted using this form will only be shown on the website if they are approved by the administrators of this site. IF APPROVED, COMMENTS MAY TAKE SEVERAL DAYS TO BE POSTED.

Posted By: (Optional)

Comments:


Other TechBytes: