Friday, May 09, 2008 2:35 PM
Does anyone know how I can export/import registry keys/subkeys programmatically in C# and .NET? I cannot find a way using Microsoft.Win32 namespace.
Friday, May 09, 2008 4:02 PMYou can use RegSaveKey and RegRestoreKey. They are not part of .Net BCL and you must pinvoke Windows API directly. However, you need SeBackupPrivilege and SeRestorePrivilege for these APIs. Normally, only members of Administrators and Backup Operators group have the privilege.
You can also use RegistryKey.GetSubKeyNames to travel the hierarchy of the registry and save each subkey individually in your own format.see Import/Export registry sections as XML for one example.
Thursday, November 26, 2009 11:00 AMThat code is horrible.
Thursday, June 30, 2011 9:00 AM
public void ExportKey(string RegKey, string SavePath)
string path = "\"" + SavePath + "\"";
string key = "\"" + RegKey + "\"";
var proc = new Process();
proc.StartInfo.FileName = "regedit.exe";
proc.StartInfo.UseShellExecute = false;
proc = Process.Start("regedit.exe", "/e " + path + " " + key + "");
if (proc != null) proc.WaitForExit();
if (proc != null) proc.Dispose();
- Proposed As Answer by SivaPrasanth Wednesday, August 10, 2011 6:06 AM