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.
Note
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.
Information
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 conversion equivalents 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):
The vast majority of registry edits will pertain to one or more of the first three roots listed above.
The primary commands used will be REG ADD and REG DELETE (see below for examples of the syntax).
Code:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>reg add /?
REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]
KeyName [\\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the
current machine. Only HKLM and HKU are available on remote
machines.
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY.
/v The value name, under the selected Key, to add.
/ve adds an empty value name (Default) for the key.
/t RegKey data types
[ REG_SZ | REG_MULTI_SZ | REG_EXPAND_SZ |
REG_DWORD | REG_QWORD | REG_BINARY | REG_NONE ]
If omitted, REG_SZ is assumed.
/s Specify one character that you use as the separator in your data
string for REG_MULTI_SZ. If omitted, use "\0" as the separator.
/d The data to assign to the registry ValueName being added.
/f Force overwriting the existing registry entry without prompt.
Examples:
REG ADD \\ABC\HKLM\Software\MyCo
Adds a key HKLM\Software\MyCo on remote machine ABC
REG ADD HKLM\Software\MyCo /v Data /t REG_BINARY /d fe340ead
Adds a value (name: Data, type: REG_BINARY, data: fe340ead)
REG ADD HKLM\Software\MyCo /v MRU /t REG_MULTI_SZ /d fax\0mail
Adds a value (name: MRU, type: REG_MULTI_SZ, data: fax\0mail\0\0)
REG ADD HKLM\Software\MyCo /v Path /t REG_EXPAND_SZ /d ^%systemroot^%
Adds a value (name: Path, type: REG_EXPAND_SZ, data: %systemroot%)
Notice: Use the caret symbol ( ^ ) inside the expand string
C:\Windows\system32>
Code:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>reg delete /?
REG DELETE KeyName [/v ValueName | /ve | /va] [/f]
KeyName [\\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current machine.
Only HKLM and HKU are available on remote machines.
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY.
ValueName The value name, under the selected Key, to delete.
When omitted, all subkeys and values under the Key are deleted.
/ve delete the value of empty value name (Default).
/va delete all values under this key.
/f Forces the deletion without prompt.
Examples:
REG DELETE HKLM\Software\MyCo\MyApp\Timeout
Deletes the registry key Timeout and its all subkeys and values
REG DELETE \\ZODIAC\HKLM\Software\MyCo /v MTU
Deletes the registry value MTU under MyCo on ZODIAC
C:\Windows\system32>
Due to the length of this Tutorial, the actual examples will be in the following post.
Need more help? Try searching our extensive help and support site.
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 and finally by how the entry actually appears in the Registry Editor.
This shows how to enter an empty value name (Default) for the key. Note that this CANNOT be deleted without deleting the parent key.
Code:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Test]
@=""
Code:
@ECHO OFF
REG ADD "HKCU\Test" /ve /f
This shows a Default variable with data.
Code:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Test]
@="Some data"
Computer type PC/Desktop System Manufacturer/Model Number Dwarf Dwf/11/2012 OS Windows 7 Ultimate x64 Service Pack 1 CPU Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.2GHz) Motherboard ASRock Z77 Extreme4-M Memory 4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB) Graphics Card 2 x AMD Radeon HD7770 1GB CrossFired (OC 1100MHz/1250MHz) Sound Card Realtek High Definition on board solution (ALC 898) Monitor(s) Displays ViewSonic VA1912w Widescreen (VGA) Screen Resolution 1440x900
Keyboard Microsoft Comfort Curve Keyboard 3000 (USB) Mouse Microsoft Comfort Mouse 3000 for Business (USB) PSU XFX Pro Series 850W Semi-Modular Case Gigabyte IF233 Cooling 1 x 120mm Front Inlet 1 x 120mm Rear Exhaust Hard Drives OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0 Internet Speed NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2) Antivirus Avast! 8.0.1483 Browser IE 9 Other Info Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
CTF-430 Tablet & Pen
WEI Score: 7.7/7.9/7.4/7.4/7.9
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\exefile\shell\Run with Normal Priority]
@=""
[HKEY_CLASSES_ROOT\exefile\shell\Run with Normal Priority\Command]
@="cmd.exe /c start \"Run with Normal Priority\" /Normal \"%1\""
Code:
@ECHO OFF
REG ADD "HKCR\exefile\shell\Run with Above Normal Priority" /ve /f
REG ADD "HKCR\exefile\shell\Run with Above Normal Priority\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with Above Normal Priority\" /AboveNormal \"%%1\"" /f
Computer type PC/Desktop System Manufacturer/Model Number Dwarf Dwf/11/2012 OS Windows 7 Ultimate x64 Service Pack 1 CPU Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.2GHz) Motherboard ASRock Z77 Extreme4-M Memory 4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB) Graphics Card 2 x AMD Radeon HD7770 1GB CrossFired (OC 1100MHz/1250MHz) Sound Card Realtek High Definition on board solution (ALC 898) Monitor(s) Displays ViewSonic VA1912w Widescreen (VGA) Screen Resolution 1440x900
Keyboard Microsoft Comfort Curve Keyboard 3000 (USB) Mouse Microsoft Comfort Mouse 3000 for Business (USB) PSU XFX Pro Series 850W Semi-Modular Case Gigabyte IF233 Cooling 1 x 120mm Front Inlet 1 x 120mm Rear Exhaust Hard Drives OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0 Internet Speed NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2) Antivirus Avast! 8.0.1483 Browser IE 9 Other Info Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
CTF-430 Tablet & Pen
WEI Score: 7.7/7.9/7.4/7.4/7.9
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)