none
how to export multiple registries to single text file in c# RRS feed

  • Question

  • proc.StartInfo.FileName =

    "regedit.exe";

    proc.StartInfo.UseShellExecute =

    false;

    string cmd = "regedit.exe" + " " + "/e" + " " + savePath + " " + RegKey;

    proc =

    Process.Start("regedit.exe", "/e " + " " + savePath + " " + RegKey); Regkey is array of strings

    Monday, July 1, 2013 11:22 AM

Answers

  • You could use the Microsoft.Win32.Registry.GetValue method to read a registry key and then use the StreamWriter  class to write the values to an output file:

    string installRoot = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\", "InstallRoot", null);
                if (installRoot != null)
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\exportfile.txt"))
                    {
                        sw.WriteLine(installRoot);
                    }
                }
    
    In the above code example I am getting a single value from the registry but you can loop through your array of keys and use the method to get the value for each key.
    Monday, July 1, 2013 11:45 AM

All replies

  • You could use the Microsoft.Win32.Registry.GetValue method to read a registry key and then use the StreamWriter  class to write the values to an output file:

    string installRoot = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\", "InstallRoot", null);
                if (installRoot != null)
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\exportfile.txt"))
                    {
                        sw.WriteLine(installRoot);
                    }
                }
    
    In the above code example I am getting a single value from the registry but you can loop through your array of keys and use the method to get the value for each key.
    Monday, July 1, 2013 11:45 AM
  • Thanks...am looking for a way by using regedit.exe...is it possible to give multiple nodepaths while executing regedit.exe /e..
    Monday, July 1, 2013 12:40 PM
  • I don't think so, you'll have to execute a command per key in your array.
    Monday, July 1, 2013 1:06 PM