How to merge registry file

rapture

Member
Joined
May 19, 2005
Messages
10
Programming Experience
Beginner
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)
Sleep((6000))

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

Thanks
 
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.

http://www.devx.com/dotnet/Article/7914/0/page/1

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()

Try
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"
myProcess.Start()
myProcess.WaitForExit(6000)
If Not myProcess.HasExited Then
myProcess.Kill()
MessageBox.Show("Process is killed", "Process Handling Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
myProcess.Close()
Catch e As Exception
MessageBox.Show(e.Message & ". Setup was unable to update the registry.", "Registry Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
 
Back
Top