Reputation: 1614
I want to take the backup of all registry keys at once using c#. I search for it but a lots of hints for a specific registry key backup but not for all keys. So if any one knows that how to take backup of all registry keys or any method to export all registry in c# kindly tell me. Thanks
Upvotes: 1
Views: 2034
Reputation: 1614
After more search i found two solutions the first one is a link And the second one is by using SendKeys. Now here is my code to export all registry keys. But for doing this first you have to start your visual studio as administrator and then start regedit then run this code.
Process[] processlist = Process.GetProcesses();
string title = "";
foreach (Process process in processlist) {
title = process.MainWindowTitle;
if (title == @"Registry Editor" && process.MainWindowHandle != IntPtr.Zero) {
SetForegroundWindow(process.MainWindowHandle);
Thread.Sleep(2000);
SendKeys.SendWait("%+F+E");
Thread.Sleep(500);
SendKeys.SendWait("%+A");
Thread.Sleep(500);
SendKeys.SendWait("%+S");
Thread.Sleep(500);
SendKeys.SendWait("TEST");
Thread.Sleep(500);
SendKeys.SendWait("%+S");
Thread.Sleep(1000);
SendKeys.SendWait("%+{TAB}");
break;
}
}
And the supported functions are
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
Upvotes: 3