RegTool - Use RegEdit in Batch Mode - September 1999

One of the companies that I work with changed their name. They changed from 'Management MarketPlace' to 'Cerebyte'. I have been saving lots of application settings using the company name as part of the registry key. I looked for a way to 'mass' convert the registry key. I did some research and discovered that RegEdit can be run in 'batch' mode. So I wrote some routines that will 'export' registry information to an ASCII text file, modify the file, then 'import' the file back into the registry. So this becomes the tip-of-the-month. Written in Coos Bay, Oregon while on Trip USA.

The Demo Program

I wrote a VB6 demo program that exports registry entries, modifies them then imports the changed items. The demo program:

RegTool Demo

Using the Demo

Starting Export Key - Enter the fully qualified 'starting' key. You could use RegEdit to 'cut' and 'paste' the key into this field. If you leave the field blank the entire registry will be exported - taking a lot of time and disk space.

Export to File - Export the registry items to this file. A temporary file name is created in folder 'Temp' under 'app.path' when you first start the application. Click 'Temp File' to create another temporary file. The temporary file is deleted if never used. If used, it is not deleted. You could enter a file name of your choice in which case its folder must already exist.

Old Value - New Value - After the file is created you can use the 'Modify Exported File' command button to change all references of 'Old Value' to 'New Value'. Be sure to restrict the replacements. Don't change 'a' or 'A' to 'X' because all a's and A's in the file would be changed to X's. In the above example all references to the company name 'The Bridge' in key 'HKEY_CURRENT_USER\Software' will be changed to 'BuyGold'. The search is case insensitive. All reference to 'the bridge' would also be changed. Once modified, click the 'Import the Exported File Into Registry' button to update the registry.

You could 'export' the settings into a file then 'carry' that file to another machine and import the settings on the new machine. If you export then import without making any changes the registry entries will 'overwrite' existing entries - effectively doing nothing.

Skip RegEdit Messages During Import - RegEdit issues a warning message and a success message unless the silent [/S] switch is set. Check this box to avoid displaying the following messages:

RegEditWarning.jpg (15221 bytes)

RegEditSuccess.jpg (14628 bytes)

RegTool Uses

RegTool Uses - If you use RegTool in your application you will need to include three modules:

RegToolNeeds.jpg (12057 bytes)

modRegTool.bas - This module is used to export, modify and import the registry entries. You call routines in this module.

modShellAndWait.bas - This module is used by modRegTool.bas to shell to RegEdit and wait for it to finish execution. See: ShellAndWaitWithTerminate for more information about this topic.

modTempName.bas - This module provides the temporary file name. See: TempNamePlease for more information about this topic.

Microsoft Scripting Runtime - The exported file is modified using the FileSystemObject which is part of the Scripting Runtime library [SCRRUN.DLL]. See: Using the File System Object to Read and Write ASCII Files for details - last months tip. You will need to reference it in your application.

Updated November 16, 1999

RegEdit 5 - RegEdit, as distributed with Windows 2000 Pro RC2, exports the registry using Unicode. RegTool was modified to accept Unicode.

The Demo Uses modConnectToWebSite

The demo program uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.

Download VB Code

Click here to download the VB 6 Source Code [23k].

Previous Tip   Tip Index   Next Tip 


Updated 2000/10/29