How to merge registry file


May 19, 2005
Programming Experience
Please bear with me as I am completely new to VB. I am trying to create an install procedure and part of it requires that a number of registry values be set. I have all these settings saved to a .reg file which was created by exporting the appropriate branch from another PC where the settings were correct. I would like to simply merge the settings using a call from the VB code.

I am trying the following code in VB.Net but nothing seems to be getting merged when I check the registry:

Call Shell("c:\windows\regedit.exe /s " + "install.reg", AppWinStyle.Hide)

I don't want to have to write numerous "regKey.setValue" lines of code to achieve this.

The default action for a .reg file is adding its contents to the registry. Without having tested it, I would expect that you should be able to use Process.Start("install.reg"). You will presumably need to qualify the file path and you may want to use a different overload of Process.Start() if you need to want more control.
Solved, with your advice

Thankyou for that invaluable tip. It helped me in the right direction and I was able to find additional information about this from the following article.

Simply using Process.Start("install.reg") worked, but it displayed prompt asking whether it "should add contents to registry" as well as displayed message saying "contents added successfully". To avoid this I used code below. It would be great if someone could tell me whether my coding style is satisfactory, as I am fairly new to this. Any pointers would be appreciated. I know I am using a fairly general class for the exception handling but this seems to get the job done.

Dim myProcess as New Process()

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.Arguments = "/C cd " & InstallPath & " && regedit.exe /s install.reg"
If Not myProcess.HasExited Then
MessageBox.Show("Process is killed", "Process Handling Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch e As Exception
MessageBox.Show(e.Message & ". Setup was unable to update the registry.", "Registry Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try